django admin list_filter“或”;健康)状况 [英] django admin list_filter "or" condition
问题描述
很抱歉,如果以前已经回答过这个问题,但是我做了很多谷歌搜索却没有成功。
我知道如何创建自定义的 list_filter
在管理员视图中(例如,将 SimpleFilter
子类化)。
我真正想要的是(在管理列表视图上)检查不同过滤器的一种方法,这些过滤器将它们组合为OR公式。
例如,假设您有:
#models.py
class Foo(models.Model):
foobar = ...
foofie = ...
...
#admin.py
类FooAdmin(admin.ModelAdmin):
list_filter =( foobar, foofie)
...
在 FooAdmin
生成的管理列表视图中,我可以选择按 foobar
或 foofie
。是否可以通过以下公式过滤它们: foobar = X或foofie = Y
,其中 X
和 Y
是 foobar
和 foofie
可以假定的两个值?
有可能吗?
我知道在django管理员视图中并非一切皆有可能,但似乎常见的要求,我想知道我是否错过了理解或阅读的东西。
也欢迎第三方应用允许它。谢谢:)
我刚刚找到了第三方应用程序,它是
sorry if this question has been answered before, but I did a lot of googling without success.
I know how to create custom list_filter
s in admin views (e.g. subclassing SimpleFilter
).
What I really would like, is a way (on the admin list view) to "check" different filters that combines them in a OR formula.
As an example, suppose you have:
# models.py
class Foo(models.Model):
foobar = ...
foofie = ...
...
# admin.py
class FooAdmin(admin.ModelAdmin):
list_filter = ( "foobar", "foofie" )
...
In the admin list view generated by FooAdmin
I can choose to filter records either by foobar
or by foofie
. Is there a way to filter them by the formula: foobar = X OR foofie = Y
, where X
and Y
are two values that foobar
and foofie
can assume?
Is it even possible?
I know not everything is possible in the django admin views, but it seems a very common request, I wonder if I missed to understand or read something.
Also third party apps allowing it are welcome. Thanks :)
I found a third party app just now, it is django-advanced-filters which may fit you requirement .
It has:
The OR field
OR is an additional field that is added to every rule's available fields.
It allows constructing queries with OR statements. You can use it by creating an "empty" rule with this field "between" a set of 1 or more rules.
I have run a test, add a OR field
would work.
This is the screenshot:
这篇关于django admin list_filter“或”;健康)状况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!