Django OR Querysets using Binary Operator
One of Django’s cool (maybe the coolest) and undocumented feature is being able to OR and AND queries using bitwise (& and |) operators. It is a variation to the Q object that is documented. for r in ( MyTable.objects.filter(somefield=’a’) | MyTable.objects.filter(someotherfield=’b’) ).filter(somethird=’c’): print r Now this becomes really useful when you use related_managers: for…
continue reading
No Comments