>  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() ) 

I actually really like this. It's simple, clear, and gets around the issues 
being discussed. It still requires Expressions to know about ordering (to 
implement the asc/desc methods) but I think that's fine.

The other problem with having ordering objects being of a different type 
means that you would have to call asc or desc. But now I think of it, the 
order_by method could just call asc, by default, on any expressions passed 
in.

Think you've come up with a winner here.

Cheers,

On Wednesday, 11 June 2014 20:58:04 UTC+10, Shai Berger wrote:
>
> 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/c101f9f8-6b57-48b2-8019-26280be4b9e5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to