Funnily enough, I'd already seen that patch but I hadn't figured out the full significance of it. I attempted to solve #22288 (https://code.djangoproject.com/ticket/22288), but spotted that your patch would possibly solve the problem entirely, and at the very least breaks my attempt to solve that specific case.
The expression concept seems like a good direction to be going in. I'd definitely be interested in seeing how to extend this to solve the two tickets I'm working on. I'll take a look at your code and see what I can do with it, and ask if I get stuck. Tim On Sunday, 1 June 2014 09:46:02 UTC+1, Josh Smeaton wrote: > > I would like to point you towards a patch I'm currently working on which > is essentially your option 2: https://github.com/django/django/pull/2496 > > It doesn't seem very relevant at first, since it only applies to .annotate > and .aggregate, but the infrastructure behind it certainly does. In short, > the patch expands on the concept of "Expressions". Expressions are nodes in > a tree that output SQL. Functions can be expressions, a field (F() object) > can be an expression, or the number 5 can be an expression. Funnily enough, > I implemented the SQL `Lower` function as a test: > https://github.com/jarshwah/django/commit/362fec1330f1f40c45ece5769f9e35047c87a010#diff-4c9f3e475cf7fa25e6d21c2fb7b8c30fR185 > > What I'd like to do if this patch is accepted (and I believe it will be > for 1.8; it's a matter of getting the backwards-compat right), is to expand > the concept of expressions into the other pieces of the API, especially > `order_by`. Once order_by understands expressions, it's trivial to order > the result set by any kind of sql you could imagine.. > > - .order_by(NullsLast('field')) > - .order_by(Lower('field')) > - .order_by(Coalesce(F('field'), F('otherfield'))) > etc. > > Marc is right that custom transforms could be used if order_by was taught > the API. I would prefer to teach order_by about Expressions though, since > F() supports custom lookups and transforms already. His version would then > look like: .order_by(F('title__lower')). I can see the value in a > keyword__based API that is similar to the rest of django (like .filter()), > but I find the syntax limiting when trying to compose multiple expressions > together. > > If you were interested in branching off and working on bringing the same > functionality to order_by, I'd be happy to provide information or support > if you had any questions. > > Regards, > > Josh > > -- 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 [email protected]. To post to this group, send email to [email protected]. 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/09acb528-94ca-4529-a8f1-9267de180b6b%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
