Thanks Malcolm for a speedy response! I guess my best bit is to somehow output the QuerySet into a list which I can then order myself (although this seems a bit ugly!), or have a rethink about the design of the two models.
Thanks again, Mike. On Jul 9, 2:07 pm, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: > On Wed, 2008-07-09 at 05:51 -0700, [EMAIL PROTECTED] wrote: > > [...] > > > I tried using the order_by with two sets of dates: > > > .order_by('-related_name_to_model__date_field_in_B', '- > > date_field_in_A') > > > However, this just produces a queryset that is partitioned into two > > separate date orderings. > > > What I'm asking is if there is anyway to "intermix" the dates so that > > ALL of the Model As appear in date order, even if they do not have a > > related Model B date? > > No, because ordering is done at the SQL level and Django converts that > ordering tuple to a sequence of ordering columns. What is happening here > (why the sets appear to be partitioned) is because all rows that don't > have a date field in B have a NULL in that column after the outer join. > All those NULLs sort together (whether they sort first or last is > database dependent) and then model A date field is used as a secondary > ordering to distinguish any rows that have sorted together for the "date > in B" columns (e.g. the NULLs). > > If you were writing the raw SQL, you could do this with a coalesce > statement in the ordering clause. Right now that kind of stuff isn't > possible to insert directly via Django, although you could do it by > subclassing Query (and then QuerySet) if you were really keen. Adding a > way to have "smart" ordering objects (you pass in an object and Django > will call the as_sql() method on it, for example) will probably happen > at some point, but it's not high priority at the moment. > > Regards, > Malcolm --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---