Sort DateTimeField only by date

0

I wanted to sort DateTimeField just by date, ignoring the time.

Because in my ordering I need

Person.objects.order_by('-date_joined', 'full_name')

But sorting by name has no effect because the field has time, but I just wanted the date.

    
asked by anonymous 30.06.2016 / 20:37

1 answer

1

Try using .extra

resultado = Person.objects.extra(select = 
{'date_only': 'to_date(date_joined)'}).order_by('-date_only', 'fullname')
    
05.07.2016 / 18:17