Sort Datetimefield by date only

Asked

Viewed 165 times

0

I wanted to order DateTimeField by date only, ignoring the time.

Because in my ordination I need to

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

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

1 answer

1


Try using the . extra

resultado = Person.objects.extra(select = 
{'date_only': 'to_date(date_joined)'}).order_by('-date_only', 'fullname')
  • has already been answered here http://stackoverflow.com/a/38151686/802542 Thank you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.