开发者

Django queryset dynamic filtering

I have a query that looks like this:

cls.objects.filter(name__in=lookup_values).values(开发者_JAVA技巧):

The problem is that sometimes I want to filter by name but other times I want to filter by, say, officer_number or customer_number. Is there a way for me to dynamically set the whatever__in part of the query so it's not hard-coded?


Do you mean something like:

args = {'id__in':[1]}

qs = Something.objects.filter(**args)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜