>>>fromdjango.db.modelsimportF,Q,When>>># String arguments refer to fields; the following two examples are equivalent:>>>When(account_type=Client.GOLD,then='name')>>>When(account_type=Client.GOLD,then=F('name'))>>># You can use field lookups in the condition>>>fromdatetimeimportdate>...
The two SQL statements are functionally equivalent but the more explicit FILTER may perform better. Conditional filter¶ When a conditional expression returns a boolean value, it is possible to use it directly in filters. This means that it will not be added to the SELECT columns, but you ca...