I have a complex Q object created dynamically. How do I negate the Q object so that it can be used in filter()
instead of exclude()
?
Use ~
operator:
complex_condition = ~Q(....)
According to Complex lookups with Q objects:
Q
objects can be negated using the ~ operator, allowing for combined lookups that combine both a normal query and a negated (NOT) query
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With