Wagtail:如果模型具有ForeignKey关系,那么片段是否可以使用InlinePanel?

时间:2016-03-31 15:05:03

标签: wagtail

我遇到的情况是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是一个页面,这是否可行?

1 个答案:

答案 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')
    ]