I am trying to create a list of birth days, ordered by the dates, my query set is:
birth_days = get_list_or_404(UserProfile.objects.order_by('-birthDate'), birthDate__month=datetime.datetime.now().month)
How can i get the list ordered by the day in month so the birth days list will be ordered, right now it is ordered by all the date, so if two people has a birth day this month and person 1 date is lets say 20/7/1980 and person 2 date is 17/7/1970, person 2 will still be after person 1 in the list. I don’t care about the year of birth, just the month and the day in month….
Can i do the in order_by something like this:
order_by(‘-birthDate__day’)
I know i can’t do that because this isn’t working, just asking if there is a way to do it (in the view, not in the model in this case…not that I think it matters over here, just saying)?
Thank you,
Erez
You can extract the day as an “extra” field and then sort on that, for example:
This should work with PostgreSQL at least.