Probably just because there hasn't been an immediate need, and because it
working on every database the same way could be... awkward. When you have
dates, you also have to think about the timezone implications as well -
which timezone do you need that date in?
It's also worth mentioning that if you don't care about those subtleties
for your application, you can use Func() to do this:
.annotate(day_created=Func(Value('day'), 'created_date',
function='date_trunc'))
https://docs.djangoproject.com/en/1.9/ref/models/expressions/#func-expressions
On 2 March 2016 at 11:44, Sam Peka <[email protected]> wrote:
> It would be great if there was a way within the standard Queryset api to
> annotate ranges of dates. The use case is that it would remove the need to
> resort to RawSQL when grouping things by date ranges, such as the day of
> the month. I know the postgres extras package has a DateRangeField, but
> it's surprisingly difficult to do this dynamically.
>
> So I'd propose something like this:
>
> queryset.annotate(day_created=DateRange('day', 'created_date'))
>
> Which for Postgres would equate to:
>
> SELECT date_trunc('day', "created_date") as day_created from ...
>
> Is there a technical reason why this hasn't already been done? Or has
> there not been much of a need for it?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django developers (Contributions to Django itself)" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/django-developers.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-developers/fe7dcfc9-cbb5-439b-bf08-f45e854a99c6%40googlegroups.com
> <https://groups.google.com/d/msgid/django-developers/fe7dcfc9-cbb5-439b-bf08-f45e854a99c6%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
--
You received this message because you are subscribed to the Google Groups
"Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-developers/CAMwjO1HTh4pFyWSDPXQ1L-_2QznoDo%3DDYUoELDDiKv5ASiYykg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.