I have this query
query = 'select * from products where (productnr, supplier_id) in (%s)' % product_list
where product_list looks like this ((OB520, 3),(RH402, 20)...)
How do I go about doing this in Django using queryset and the __in filter
I have this query
query = 'select * from products where (productnr, supplier_id) in (%s)' % product_list
where product_list looks like this ((OB520, 3),(RH402, 20)...)
How do I go about doing this in Django using queryset and the __in filter
Comma-delimit the query.
Example:
Sometimes it's better to answer the question rather than to bicker about it being a valid question.
What part of this is confusing? http://docs.djangoproject.com/en/1.2/ref/models/querysets/#in It seems very clear.
It's not perfectly clear from the question what the problem is.
Are you asking how to use a multi-part key? If so, you're going to be unhappy with simple
__in
.If you're trying to look for an "OR" of a two-part key, you have to create a more complex condition.
Start here: http://docs.djangoproject.com/en/1.2/topics/db/queries/#complex-lookups-with-q-objects
If you're trying to do multi-key lookups, this is they way it has to work.
Or, is the problem that your "in" clause has a long list of specific values?
If you have a long list, you might want to build the query in pieces.
The above is untested. Also, it's probably inefficient.
What's better is something like this.
That will do a number of very efficient SQL lookups one at a time. That may execute faster than building a complex multi-key IN clause.