Skip to content

Instantly share code, notes, and snippets.

@kaedroho
Last active August 29, 2015 13:59
Show Gist options
  • Save kaedroho/10968400 to your computer and use it in GitHub Desktop.
Save kaedroho/10968400 to your computer and use it in GitHub Desktop.
from django.db import models
from modelcluster.fields import ParentalKey
from wagtail.wagtailcore.models import Page, Orderable
from wagtail.wagtailadmin.edit_handlers import FieldPanel, InlinePanel
class Thing(models.Model):
...
class PageThings(models.Model): # Inherit from Orderable if you would like reorder
page = ParentalKey('myapp.MyPage', related_name='things')
thing = models.ForeignKey(Thing, related_name='pages')
panels = [
FieldPanel('thing')
]
class MyPage(Page):
...
def get_things(self):
return Thing.objects.filter(pages__page=self)
MyPage.content_panels = [
InlinePanel(MyPage, 'things', label="Things"),
...
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment