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?
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')
]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With