簡體   English   中英

鶺鴒:根據當前object動態限制選擇

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM