On Mon, Sep 26, 2011 at 3:12 PM, j_syk <jesyk...@gmail.com> wrote: > Hello- > On Friday afternoon I migrated a project from sqlite to postgres. > Everything went smoothly and I was able to go home for the weekend and > be happy. Yay. > This morning I was informed that the sort order is different. I have a > DateField for a due date that is set as not required, however leaving > it blank treats it as ASAP. I'm assuming this is a result of the > different sort orders between sqlite and postgres. I got used to > sqlite sorting it like: "None, Oct, Dec, etc." but now I am getting > "Oct, Dec, etc., None". > > Here are the options I'd rather not do: > -Go back to sqlite > -set the default as some date years ago and override the display value > in templates (I already use this method to make a None show as "ASAP") > i.e. {% if item.due_date == '1999-1-1' %}ASAP{% else %} > {{ item.due_date }}{% endif %} > -add another field to the model, a boolean field for ASAP, set it to > true if the due date is blank and sort by that first (this may > actually be a decent option) > > I'm hoping there is a setting in postgres that can be changed for the > sort priority of null. > Is this any easy way to solve this problem before I start reworking > all the code? >
You can control the order of how nulls sort with pgsql (at least, 8.3 and above) by appending 'NULLS FIRST' or 'NULLS LAST' to the 'ORDER BY' clause of a select query. I'm not aware of a way to administratively choose 'NULLS FIRST' for all queries, and you may find it tricky getting 'ORDER BY ... NULLS FIRST' into a django produced query. Cheers Tom -- 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 django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.