L
L
Lopus2016-04-10 18:10:19
Django
Lopus, 2016-04-10 18:10:19

How to sort by DateTimeField but only by date (django)?

There is a field DateTimeField.
It is necessary to sort so that time is not taken into account.
As a result, you need to sort the result by date, and then by rating. If time is taken into account in this sorting, then sorting by rating will be meaningless

Answer the question

In order to leave comments, you need to log in

3 answer(s)
P
Peter, 2016-04-10
@Lopus

Foo.objects.extra(select={'d_field': 'date(<field name>)'}).extra(order_by=['d_field'])

B
Bulat Kurbangaliev, 2016-04-10
@ilov3

Since version 1.9 you can do this:
Bar.objects.all().order_by('my_date_time_field__date')
prooflink: https://docs.djangoproject.com/en/dev/ref/models/q...

M
Mintormo, 2016-04-10
@Mintormo

Maybe it was necessary to immediately make separate fields for the date and time? And the problem is solved by itself.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question