[Django]-Django, Wagtail admin: handle many to many with `through`

6👍

What you need is an InlinePanel: http://docs.wagtail.io/en/v2.0.1/getting_started/tutorial.html#images

from wagtail.admin.edit_handlers import FieldPanel, InlinePanel
from wagtail.core.models import Orderable
from modelcluster.fields import ParentalKey

# the parent object must inherit from ClusterableModel to allow parental keys;
# this happens automatically for Page models
from modelcluster.models import ClusterableModel

class A(ClusterableModel):
    title = models.CharField(max_length=500)

    content_panels = [
        FieldPanel('title'),
        InlinePanel('ab_objects'),
    ]

class AB(Orderable):
    a = ParentalKey('app.A', related_name='ab_objects')
    b = models.ForeignKey('app.B')
    panels = [
        FieldPanel('b'),
    ]
👤gasman

Leave a comment