![](/img/trans.png)
[英]Django Admin - Filter Choice Field based on current object being edited
[英]Wagtail: Limit choice dynamically based on current object
如何限制 wagtail admin 中 districtobject 字段的选择?
class DistrictPage(Page):
districtobject = models.ForeignKey(DistrictTranslated, on_delete=models.SET_NULL, null=True, blank=True)
我知道我可以使用“limit_choices_to”作为 Q 的基本限制。但我想使用一种更动态的方法,它允许我使用当前 object 的“内容”。(如 self.attribute ...等)
例如:
def my_limit_function(self):
1. get parent page
2. read date from parent page and extract this information for a filter query
我不认为你可以在页面 class 定义中做到这一点。 我认为您将需要像文档中的这个示例一样自定义页面表单。 这些值可以以__init__.py
的形式设置。 不要忘记,在您的页面第一次保存之前不会有父页面。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.