Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wagtail: Can snippets have InlinePanel if the model has a ForeignKey relationship?

Tags:

wagtail

I've got the situation where a Wagtail snippet is a model that has a FK relationship. I can't figure out how to make that available in the CMS as an inline.

Given:

@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)

how do I allow Task to be an inline to TeamMember?

Or is this only possible if TeamMember is a Page?

like image 479
Bob Donahue Avatar asked Mar 31 '16 15:03

Bob Donahue


1 Answers

You need to change the ForeignKey to ParentalKey. You may also need to change the TeamMember class to inherit from 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')
    ]
like image 99
chrxr Avatar answered Oct 09 '22 11:10

chrxr