I have a categorypage -> articlepage hierarchy in wagtail. The article page has an author field, which currently shows all users in the system. I want to filter the authors of the article based on the group of the parent category page.
models.py
from django.contrib.auth.models import Group
class CategoryPage(Page): # query service, api
blurb = models.CharField(max_length=300, blank=False)
content_panels = Page.content_panels + [
FieldPanel('blurb', classname="full")
]
subpage_types = ['cms.ArticlePage']
class ArticlePage(Page): # how to do X with query service
...
author = models.ForeignKey(User, on_delete=models.PROTECT, default=1,
# limit_choices_to=get_article_editors,
help_text="The page author (you may plan to hand off this page for someone else to write).")
def get_article_editors():
# get article category
# get group for category
g = Group.objects.get(name='??')
return {'groups__in': [g, ]}
This question (limit_choices_to) is almost what I'm after, but I'm not sure how to retrieve the group for the parent page before the article itself is created?
This question seems to do the trick in accessing parent pages on creation, but I remain unsure of how to find the groups that can edit the parent page.