[英]How to create a filter in Django with two different status
I want to create a filter in Django admin which would return records with two different statuses by single "filter" defined as one of: 我想在Django admin中创建一个过滤器,它将返回具有两种不同状态的记录,单个“过滤器”定义为以下之一:
def lookups(self, request, model_admin):
return (
('1', 'class 1'),
('2', 'class 2'),
('3', 'class 3'),
('4', 'class 3')
)
I'm using an API that returns to me all statuses with two extra statuses which I don't need. 我正在使用一个API,它返回给我所有状态,有两个额外的状态,我不需要。
def queryset(self, request, queryset):
if self.value() == 'all':
return queryset.filter()
else:
return queryset.filter(client__status=self.value())
In my filter list I want to have just one logical item clients with status x
which would give me all clients with status M and status N. 在我的过滤器列表中,我想只有一个clients with status x
逻辑项clients with status x
,它将为我提供状态为M且状态为N的所有客户端。
def queryset(self, request, queryset):
if self.value() == 'all':
return queryset.all()
elif self.value() == 'clients with status x':
return queryset.filter(client__status__in=['M', 'N', ])
else:
return queryset.filter(client__status=self.value())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.