Reputation: 1105
I wanted to order a query set on the basis of a time of a datetime field. I have used the following (here Tasks is my model and datetime is the field)
Tasks.objects.all().order_by('datetime.time')
this doesn't work and also
Tasks.objects.all().order_by('datetime__time')
doesn't work as it is part of the same model.
I tried using .annotate()
but I don't know how exactly to do it.
How should I go about doing this?
Upvotes: 2
Views: 8561
Reputation: 27513
Tasks.objects.all().order_by('datetime__hour')
or
Tasks.objects.all().order_by('datetime__minute')
Upvotes: 7