Is it possible to change Django Q () objects after building?

Is it possible to change Django Q () objects after building? I create a Q () object as follows:

q = Q(foo=1)

can be changed later qas if I built:

q2 = Q(foo=1, bar=2)

? There is no mention of such an interface in the Django docs that I could find.

I was looking for something like:

Q.append_clause(bar=2)
+4
source share
2 answers

You can simply create another Q () and AND object together: q2 = q & Q(bar=2)

+5
source

You can add Q objects together using their method add. For instance:

>>> q = Q(sender=x)
>>> q.add(Q(receiver=y), Q.AND)

The second argument addis a connector, which can also beQ.OR

: - , , , filter , , , Q. filter(sender=x, receiver=y), filter(sender=x).filter(receiver=y), Q, , filter .

, SQL , .

+3

All Articles