django extra where clause (bitwise OR) with a Q object
Posted | archive
So if you want to write a Queryset in Django like this:
models.MyModel.objects.filter( Q(a=1) | Q(b=2).extra(where=[""]) )
It desn't work, because extra()
can not be used on a django.db.models.Q
object
Instead, you can write like this:
qs = models.MyModel.objects.filter(a=1)
qs |= models.MyModel.objects.filte(b=2).extra(where=[""])
I guess it's cool.
Comments