django admin list_filter“或”;健康)状况 [英] django admin list_filter "or" condition

查看:122
本文介绍了django admin list_filter“或”;健康)状况的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很抱歉,如果以前已经回答过这个问题,但是我做了很多谷歌搜索却没有成功。



我知道如何创建自定义的 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_filters 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆