Skip to content

Instantly share code, notes, and snippets.

@pjho
Created October 9, 2016 21:08
Show Gist options
  • Save pjho/f0bbcfc745989191cf305a34233388e0 to your computer and use it in GitHub Desktop.
Save pjho/f0bbcfc745989191cf305a34233388e0 to your computer and use it in GitHub Desktop.
Wagtail Related Inline Model
from modelcluster.fields import ParentalKey
from wagtail.wagtailcore.models import Page, Orderable
# The Parent/Consuming page
class ExamplePage(Page):
content_panels = Page.content_panels + [
InlinePanel('related_sub_model_label', label="Ui Heading for inline model"),
]
# The abstract class defining the fields. Can be named whatever.
class RelatedSubFieldsClass(models.Model):
heading = models.TextField()
panels = [
FieldPanel('heading'),
]
class Meta:
abstract = True
# The class that creates the relationship
class RelatesSubFieldToPage(Orderable, RelatedSubFieldsClass):
page = ParentalKey('ExamplePage', related_name='related_sub_model_label')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment