[Django]-Many-to-many relationship of wagtail page model to itself?

4👍

from modelcluster.fields import ParentalManyToManyField

class PlantPage(Page):
    related_plants = ParentalManyToManyField('self', blank=True)

    content_panels = Page.content_panels + [
        FieldPanel('related_plants'),
    ]

This relation is symmetric, if A is related to B, B is related to A.

many to many self

Docs https://docs.wagtail.io/en/stable/getting_started/tutorial.html?highlight=ParentalManyToManyField
The example uses a checkbox widget.

FieldPanel('categories', widget=forms.CheckboxSelectMultiple),

Leave a comment