Selecting multiples choices in django admin filter list_filter?

会有一股神秘感。 提交于 2019-12-22 04:32:53

问题


Currently i filter by some option in django's admin interface. For instance lets say i filter by 'By status'. Is it possible to select multiple statuses to filter results from? Here is the screenshot of the filter:

Can i select multiple items from this list?


回答1:


Not in the admin UI, but if you modify the URL, you can make the filtering criterion more complex.

For instance, now the URL (after you click on a filter) probably ends with something like

?status__exact=a

You can change this to

status__in=a%2Cm

in order to see both statuses a and m. The %2C encodes a comma.




回答2:


You can also add the following query to the URL of your list page. in my case if i have multiple option.

?bookingstatus__in=booked,refunded.



回答3:


You can also add the following query to the URL of your list display page

?my_field__gte=1&myfield__lte=10

for numeric fields. That way you can have a ranged selection. Basically you can use any query you would also use in your code.



来源:https://stackoverflow.com/questions/7834990/selecting-multiples-choices-in-django-admin-filter-list-filter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!