有没有一个优雅的方式来为Django管理中的M2M字段设置一个list_filter? [英] Is there an elegant way to have a list_filter for a M2M field in the Django admin?
问题描述
如果我有一个比萨模型和一个Topping模型,他们之间有m2m,有一些快速优雅的方式来添加到管理列表页面中的任何一个所有比萨饼的列表过滤器,其中包含一些顶部/所有浇头包含在某个比萨饼中?
If I have a Pizza model and a Topping model, with m2m between them, is there some quick elegant way to add to the admin list page for either of them a list filter for all pizzas which contain a certain topping / all toppings that are contained in a certain pizza?
内置的list_filter不支持m2m字段,所以我正在寻找一些解决方法来允许这种过滤。 / p>
The built-in list_filter doesn't support m2m fields so I'm looking for some workaround to allow this sort of filtering.
推荐答案
您可以制作自己的自定义FilterSpec。
Django 1.3或更低版本中的Django Admin中的自定义过滤器
http://djangosnippets.org/snippets/1963/
http://www.djangosnippets.org/snippets/1051/
You can make your own custom FilterSpec.
Custom Filter in Django Admin on Django 1.3 or below
http://djangosnippets.org/snippets/1963/
http://www.djangosnippets.org/snippets/1051/
这篇关于有没有一个优雅的方式来为Django管理中的M2M字段设置一个list_filter?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!