这个问题首先要说什么?
这是我的model.py
class ProjectPage(Page):
"""
A Project Page
We access the People object with an inline panel that references the
ParentalKey's related_name in ProjectPeopleRelationship. More docs:
http://docs.wagtail.io/en/latest/topics/pages.html#inline-models
"""
introduction = models.TextField(
help_text='Text to describe the page',
blank=True)
image = models.ForeignKey(
'wagtailimages.Image',
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name='+',
help_text='Landscape mode only; horizontal width between 1000px and 3000px.'
)
body = StreamField(
BaseStreamBlock(), verbose_name="Page body", blank=True
)
subtitle = models.CharField(blank=True, max_length=255)
tags = ClusterTaggableManager(through=ProjectPageTag, blank=True)
date_published = models.DateField(
"Date article published", blank=True, null=True
)
#email = models.CharField(max_length=255, blank=True, null=True)
email = models.ForeignKey(User, on_delete=models.PROTECT, to_field='email', null=True)
content_panels = Page.content_panels + [
FieldPanel('subtitle', classname="full"),
FieldPanel('introduction', classname="full"),
ImageChooserPanel('image'),
StreamFieldPanel('body'),
FieldPanel('date_published'),
InlinePanel(
'project_person_relationship', label="Author(s)",
panels=None, min_num=1),
FieldPanel('email'),
FieldPanel('tags'),
FieldPanel('added_by', classname="full"),
FieldPanel('updated_by', classname="full"),
]
search_fields = Page.search_fields + [
index.SearchField('body'),
]
added_by = models.ForeignKey(People,related_name="project_added_by", null=True, blank=True, on_delete=models.SET_NULL)
updated_by = models.ForeignKey(People,related_name="project_updated_by", null=True, blank=True, on_delete=models.SET_NULL)
created_at = models.DateTimeField(auto_now_add=True, null=True, blank=True)
updated_at = models.DateTimeField(auto_now=True, null=True, blank=True)
上述问题的解决方案是什么,如果您需要更多有关此问题的信息,请告诉我!!!!
我不知道,但我认为这里是电子邮件ID或其他地方的问题,因为在此之后可能会出现此问题,因此我添加了电子邮件ID。
答案 0 :(得分:1)
在Django的email
模型上User
的声明是:
email = models.EmailField(_('email address'), blank=True)
This part of the Django documentation说,如果您链接到默认键之外的任何其他字段(例如您尝试链接到email
的方式),则该字段必须用{{ 1}},但不是unique=True
。尝试链接的问题是email
模型的User
字段上没有索引,因为它没有声明为唯一。
像这样链接到Django用户模型会更标准(默认情况下,链接是基于用户模型的默认键id)
email
使用上述声明,您将在模板中通过from django.contrib.auth import get_user_model
user = models.ForeignKey(get_user_model(), on_delete=models.PROTECT, null=True)
收到链接用户的电子邮件,但是我不知道将用户链接到页面的体系结构。请记住,Wagtail具有权限结构,可用于为特定页面类型/模型的用户组分配权限。