Hi all im new to django(and python) and had to do something in a dirty way recently. would like to know if there is a more elegant solution.
I have a model which has lists of people with many fields including one datetime field called date_of_birth I need to show a list of people whose birthday falls on November p = Person.objects.filter(date_of_birth__month=11) Works wonderfully. Now i wanted to list them in order by the day of their birth (ignoring the year) person born on 1 Nov 1955 would be higher than someone born on 2 Nov 1933 .... The following doesnt work (Intitutively i assumed they should) p = Person.objects.filter(date_of_birth__month=11).order_by ("date_of_birth__day") or p = Person.objects.filter(date_of_birth__month=11).order_by ("date_of_birth.day") if I use :- p = Person.objects.filter(date_of_birth__month=11).order_by ("date_of_birth") It works but its not exactly what I wanted as it factors in the year as well. On asking a friend who knows python i ended up implementing :- p = Person.objects.filter(date_of_birth__month=11) people_by_day = [(person.date_of_birth.day, person) for person in p ] people_by_day.sort() p = [person_by_day[1] for person_by_day in people_by_day] Just curious if this is the right way or does the database api allow me to do this directly? As far as possible if like postgres to handle all the heavy lifting. Eventually the model in question is going to have 100,000s of records. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---