我正在使用django-allauth作为我的一个项目.我想通过ajax实现登录/注册过程.我想要自定义注册表单.我正在通过他们的signupmixin和注册表单.听起来我可以为每个动作编写自定义视图并将其映射到url配置.我不确定最好的方法是什么.
非常感谢您对此的任何帮助或建议.
django django-forms django-views django-authentication django-allauth
我想对产品及其属性使用自定义中间表。我定义了以下模型,
class Products(models.Model):
name = models.CharField(max_length=600, blank=True)
brand = models.CharField(max_length=300, blank=True)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
class Attributes(models.Model):
name = models.CharField(max_length=600)
product = models.ManyToManyField(Products, through="AttributesMapping", related_name="attributes")
class AttributesMapping(models.Model):
attribute = models.ForeignKey(Attributes)
product = models.ForeignKey(Products)
value = models.TextField(blank=True)
Run Code Online (Sandbox Code Playgroud)
在视图中将 Products 对象添加到上下文并从模板中尝试通过说来获取属性
{% for attribute in product.attributes.all %}{{ attribute.name }}: {{ attribute.value }} {% endfor %}
Run Code Online (Sandbox Code Playgroud)
我得到了名称,但值没有显示。我尝试检查正在执行的 sql 语句。
SELECT `attributes`.`id`, `attributes`.`name` FROM `attributes` INNER JOIN `attributes_mapping` ON (`attributes`.`id` = `attributes_mapping`.`attribute_id`) WHERE `attributes_mapping`.`product_id` = 1
Run Code Online (Sandbox Code Playgroud)
该值在“attributes_mapping”表中,Select 语句有一个引用但未选择该字段。
在此先感谢您的任何帮助或建议。