Re: Support for function application in ORDER BY

2014-06-08 Thread Marc Tamlyn
Agreed. It's worth noting that we could have a `Desc` operator for awkward edge cases where __neg__ doesn't work well, and the default implementation of __neg__ just returns Desc(self). I've not completely considered all the possible implications here, just throwing the idea around. On 9 June 201

Re: Support for function application in ORDER BY

2014-06-08 Thread Josh Smeaton
> That sounds like a workable approach. If I'm understanding right, this means putting the ordering flag on the ExpressionNode class so that all nodes will have this whether or not they are to be used in an ordering context? Yes, that had been what I was thinking, based upon the implementation

Re: Support for function application in ORDER BY

2014-06-08 Thread Marc Tamlyn
In my opinion, Accounts.objects.filter(balance__lt=-F('overdraft_limit')) would not change the ordering like that. I guess that's an API that doesn't work at the moment anyway. An alternative is to use ~ instead of - meaning inverse instead of negative. This might be more appropriate (but then is

Re: Support for function application in ORDER BY

2014-06-08 Thread Tim Martin
On Sunday, 8 June 2014 13:24:01 UTC+1, Josh Smeaton wrote: > > I've thought about this previously, and what I had in mind was: > > - Expressions should support an ordering parameter of some kind in the > constructor, and save it to an ordering property. Default to ASC > - If we go with Marc's sug

Re: Support for function application in ORDER BY

2014-06-08 Thread Josh Smeaton
I'm glad it was easy to implement, I was hoping that would be the case. It also means that expressions are general enough that they can be used elsewhere in the code base. Thanks for following this through! > It might be nice (although possibly impractical) to have something like order_by(-Lowe

Re: Support for function application in ORDER BY

2014-06-08 Thread Marc Tamlyn
It might be nice (although possibly impractical) to have something like order_by(-LowerCase('title')) [using __neg__ on LowerCase]. That might put logic on the "wrong" objects though. In any case, LowerCase('-title') looks weird. Naturally just passing in the string 'title' or '-title' should cont

Re: Support for function application in ORDER BY

2014-06-08 Thread Tim Martin
I've reworked my approach to ORDER BY to base it on Josh's patch, and it works very well. It's very straightforward to implement something like this: Article.objects.order_by(LowerCase('title')) --> ORDER BY LOWER("some_articles"."title") This makes use of all the existing expression compiling