简体   繁体   English

在django admin中过滤list_filter

[英]Filter list_filter in django admin

I need to filter by a field one to many but I just want to show related objects and not all. 我需要按字段过滤一对多,但我只想显示相关对象而不是全部。

is this possible, or I have to create a custom filter? 这可能,或者我必须创建自定义过滤器?

I try to keep my templates as "dumb" as possible, so I would definitely filter my data in the view. 我尽量让模板保持“哑”,所以我肯定会在视图中过滤我的数据。 You could try something like this: 你可以尝试这样的事情:

filtered_results = [ row for row in results if row['key'] == 'value' ]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM