python - How to write the query equivalent to "WHERE a0 OR a1 OR a2 ..." clause in Django -


in django, want use little complex query improving performance. want following.

query = q()  # edited: incorrect "none" replace "q()"  # don't know conditions length until program runs. # conditions contain list of list such [[x1, y1], [x2, y2] ...]   x, y in conditions:     query |= q(x=x, y=y) coordinates = coordinate.objects.filter(query)  x, y in conditions:     c = coordinates.get(x=x, y=y)     print(c)  # execute related "c" 

it works well. however, doubt best. think django has more useful , effective queries. know way?

in case, every call of print function doing database query!

query sets delay execution until time they're run. link explains how: https://docs.djangoproject.com/en/1.8/topics/db/queries/#querysets-are-lazy

execute query first, outside loop. iterate on results inside loop , print them.


Comments