【发布时间】:2018-01-30 03:37:02
【问题描述】:
我在 wagtail 中有一个 categorypage -> articlepage 层次结构。文章页面有一个作者字段,当前显示系统中的所有用户。我想根据父类别页面的组过滤文章的作者。
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) 差不多就是我所追求的,但是在文章本身创建之前不知道如何检索父页面的分组?
This question 似乎可以在创建时访问父页面,但我仍然不确定如何找到可以编辑父页面的组。
【问题讨论】: