我创建了一个可重用的抽象模型(mixin),其中包含必填字段(不含空格= True)。然后添加到页面模型内联模型,继承该mixin。最后,尽管我填写了所有必填字段,但我无法保存页面。我的应用程序崩溃了一条消息,这些字段不能为空。当我取消所需的选项时,一切运作良好。如果我使用这个模型显然(作为纯内联模型,而不是mixin)与必填字段相同的事情。这里有什么问题?如果我的方法非常复杂,那么在这种情况下重用代码的更好方法是什么?
class ContentSectionOneMixin(models.Model):
class Meta:
abstract = True
content_section_one_title = models.TextField(_('Title'), null=True)
content_section_one_body = RichTextField(_('Lead'), null=True)
content_section_button_caption = RichTextField(
_('Caption'),
null=True,
blank=True
)
content_panels = [
MultiFieldPanel(
heading=_('Content Section One'),
children=[
FieldPanel('content_section_one_title'),
FieldPanel('content_section_one_body'),
FieldPanel('content_section_button_caption'),
],
classname='collapsible collapsed'
),
]
class HomePageContentFlow(Orderable, ContentSectionOneMixin):
page = ParentalKey('HomePage', related_name='content_flow')
panels = ContentSectionOneMixin.content_panels