我想在Wagtail网站中更改客户端的BlogIndexPage的SnippetChooserPanel显示

问题描述 投票:2回答:1

我想由客户端更改BlogIndexPage的SnippetChooserPanel的显示。但是,我不打算更改显示。

我只想显示同一客户的合同。但是现在所有合同都是可见的。

我调查的内容:

Filter query set

wagtail-ModelAdmin.get_queryset()

def get_queryset(self, request):
    qs = super().get_queryset(request)
    return qs.filter(client=request.client)
django wagtail
1个回答
1
投票

这里是对我有用的解决方案:

class CustomizedChooserPanel(SnippetChooserPanel):
    def on_form_bound(self) -> None:
        self.form.fields["your_field_name"].queryset = self.model.objects.filter(client=request.client)
        super().on_form_bound()

然后在您的content_panels中:

content_panels = (
        [CustomizedChooserPanel("your_field_name")]
    )
© www.soinside.com 2019 - 2024. All rights reserved.