我使用了postgresql,我的django模型是
class SelectResources(models.Model):
collection_resource = models.ForeignKey(
'wagtailcore.Page',
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name='+'
)
content_panels = Page.content_panels + [
PageChooserPanel('collection_resource'),
]
class Meta:
abstract = True
class ResourcePageSelectResources(Orderable, SelectResources):
page = ParentalKey('ResourceCollections', related_name='selectresources')
class ResourceCollections(ResourcePage):
collection_cover_image = models.ForeignKey(
'wagtailimages.Image',
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name='+',
help_text="""
Max file size: 10MB. Choose from: JPEG, PNG
"""
)
image_text = RichTextField(blank=True,
help_text="Text that displays hover the image"
)
body_text = TextField(blank=True,
help_text="Text that displays on the body"
)
collection_heading = TextField(blank=True,
help_text="Heading of collections"
)
description = TextField(blank=True,
help_text="Short description of collections"
)
button_text = TextField(blank=True)
content_panels = Page.content_panels + [
ImageChooserPanel('collection_cover_image'),
FieldPanel('image_text', classname="full"),
FieldPanel('body_text', classname="full"),
FieldPanel('collection_heading', classname="full"),
FieldPanel('description', classname="full"),
FieldPanel('button_text', classname="full"),
InlinePanel('selectresources', label="selectresources"),
]
promote_panels = Page.promote_panels + [
FieldPanel('topic_tags'),
FieldPanel('priority'),
]
def get_context(self, request, **kwargs):
slug = ''
context = super(ResourceCollections, self).get_context(request)
context = get_data(
request, data=context, slug=slug,
path_components=kwargs.get('path_components', [])
)
return base_context(context,self)
def get_template(self, request):
return 'resources/collections_index_page.html'
当我尝试在wagtail admin中使用SelectedResources发布页面时,它会抛出错误列“id”中的IntegrityError-null值违反非空约束DETAIL:失败行包含(null,0,176,243 )
没有SelectedResources,页面按预期正确发布