Dynamic filtering of Django requests

I have a query that looks like this:

cls.objects.filter(name__in=lookup_values).values(): 

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

+4
source share
1 answer

You mean something like:

 args = {'id__in':[1]} qs = Something.objects.filter(**args) 
+9
source

Source: https://habr.com/ru/post/1343800/


All Articles