I have a [https://github.com/django/django/pull/8119 PR] that addresses
part of this: being able to have an expression that returns a value with
an `output_field` of `BooleanField` used in a `.filter()`, or a
Does this address enough of this ticket? Or provide any other suggestions?
The `.filter(F(x) == 'foo')` syntax doesn't work, and won't without quite
a bit more work (basically, I think this would require the `__eq__` method
on `F` to return a non-boolean, which I think is probably Bad News(tm).)
I think it can be spelled a different way using `ExpressionWrapper`.
Supporting boolean expressions is enough for the framework. It will be
possible for 3rd party libs to support more fluent syntaxes by converting
algebraic expressions into database expressions, similar to how combinable
works. Whether or not anyone attempts to do that is neither here nor
I think this is a really good change. Having to annotate to filter is not
just cumbersome, but as you've shown also a large performance hit.
The docs might need a little bit of work, but I think the code and tests
In [changeset:"fff5186d3215e0ba06e47090226169f2230786b0" fff5186d]:
Refs #25367 -- Moved select_format hook to BaseExpression.
This will expose an intermediary hook for expressions that need special
formatting when used in a SELECT clause.
In [changeset:"d275fd04f3fbb1a6cfa2273feb6cb414ce143b8c" d275fd04]:
Refs #25367 -- Simplified OrderBy and Lookup by using Case() instead of
RawSQL() on Oracle.
Follow up to efa1908f662c19038a944129c81462485c4a9fe8.