我遇到的情况是Wagtail片段是一个具有FK关系的模型。我无法弄清楚如何在CMS中将其作为内联提供。
假设:
@register_snippet
class TeamMember(models.Model):
name = models.CharField(max_length=80)
(other fields)
content_panels = [
FieldPanel('name'),
(etc.)
#InlinePanel('tasks', label="Team Tasks")
]
class Task(models.Model):
team_member = ForeignKey('TeamMember', related_name='tasks')
(other fields)
如何允许Task成为TeamMember的内联?
或者,如果TeamMember是一个页面,这是否可行?
答案 0 :(得分:10)
您需要将ForeignKey
更改为ParentalKey
。您可能还需要更改TeamMember类以继承ClusterableModel
。
@register_snippet
class TeamMember(ClusterableModel):
name = models.CharField(max_length=80)
panels = [
FieldPanel('name'),
InlinePanel('tasks', label="Team Tasks")
]
class Task(models.Model):
team_member = ParentalKey('TeamMember', related_name='tasks')
task = models.CharField(max_length=80)
panels = [
FieldPanel('task')
]