微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在 wagtail 中向 modelAdmin 添加多对多关系字段

如何解决在 wagtail 中向 modelAdmin 添加多对多关系字段

我在 page.py 上有(客户与页面的多对多关系):

   def printable_customers(self):
        return list(Customer.objects.filter(id__in=self.pagehascustomer_set.values_list('customer_id',flat=True)).values_list('name',flat=True))

然后我在 admin.py 上有这个

class ArticleAdmin(ModelAdmin):
    model = ArticlePage
    menu_label = 'Published'
    list_display = ('title','go_live_at','printable_customers','owner','live',)
    list_filter = ('live',)
    search_fields = ('title','printable_customers')
    ordering = ('go_live_at',)

现在我需要 printable_customers 在该模型管理员索引视图上进行排序和搜索。怎么做?在这个阶段,我可以看到可打印客户(例如公司 A、公司 B)列的数据,但上面没有排序按钮

sortable field

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。