A
A
aLap2021-09-21 13:47:01
Django
aLap, 2021-09-21 13:47:01

GROUP BY DATE(table.datetime_field) in Django?

you need to select the number by day, in sql it's easy

SELECT
    sum(some_table.items)
FROM
    some_table
WHERE
    some_table.datetime_field > '2021-09-01'
    GROUP BY DATE(some_table.datetime_field)


Is it possible to implement such a query on a django model? It's about the built-in Mysql DATE function. Google did not help, I only saw answers that in such cases raw queries to the database should be used, but these answers are old, maybe there is support in modern versions?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2021-09-21
@aLap

Why google if everything is in the documentation? Fields of type DateTimeField have a date lookup .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question