Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to modify Django Q() objects after construction?

Is it possible to modify Django Q() objects after construction? I create a Q() object like so:

q = Q(foo=1)

is it possible to later change q to be the same as if I had constructed:

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

? There's 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)
like image 464
Scott Stafford Avatar asked Sep 03 '14 14:09

Scott Stafford


1 Answers

You can just make another Q() object and AND them together: q2 = q & Q(bar=2)

like image 184
Perrin Harkins Avatar answered Oct 13 '22 04:10

Perrin Harkins