On Tuesday 10 June 2014 02:48:14 Josh Smeaton wrote:
> > However, I think having some special case code in filter(), annotate()
> 
> and anything else that takes expressions would be OK
> 
> I strongly disagree with this. Expressions are context insensitive at the
> moment, which means they can be used anywhere. If we start externalising
> behaviour based on the context of use, it'll lead us to some very confusing
> code and a tonne of special cases.

+1 Josh.

However, per the __neg__ issue, I think you're heading in the wrong direction: 
ordering shouldn't be a feature of an expression, because an expression with 
ordering cannot be used the same way: It cannot be combined with other 
expressions (because the ordering of the result is intuitively ambiguous), it 
shouldn't be used for comparisons etc.

So, I think, in terms of implementation (and I'm doing this in horrible style, 
without looking at your actual patches -- sorry if I'm way off), once you apply 
ordering to an expression, you should get a different-typed object. Indeed, a 
wrapper would be suitable, but it should no longer be an expression IMO.

And in terms of API as well -- the hints should be clear that this is different 
from normal expression creation. Both "-Expression" and "Desc(Expression)" 
look like other expressions, so I think they're suboptimal. I'd prefer 
something like "Expression.desc()" which reads nicely:

        Model.objects.filter(...).order_by( F('fld_a').desc(), 
F('fld_b')).asc() )
        Model.objects.filter(...).order_by( (F('fld_a')+F('fld_b')).desc() )

(desc as a property instead of method would read nicer but feels less "right" 
as Python).

My 2 cents,

        Shai.

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/201406111357.36512.shai%40platonix.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to