#28649: Add "week_year" lookup to DateField/DateTimeField
-------------------------------------+-------------------------------------
     Reporter:  Sigurd Ljødal        |                    Owner:  Sigurd
                                     |  Ljødal
         Type:  New feature          |                   Status:  assigned
    Component:  Database layer       |                  Version:  master
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  ORM Extract          |             Triage Stage:
                                     |  Unreviewed
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Old description:

> I found myself in the need to extract the ISO year/week-numbering year
> (as specified by ISO 8601) from a date/datetime field, e.g. to group
> values by week. This is easy with PostgreSQL:
>
> {{{
> from django.db.models.functions import Extract, ExtractWeek
>
> SomeModel.objects.annotate(
>     year=Extract('some_date', 'isoyear'),
>     week=ExtractWeek('some_date'),
> ).values(
>     'year', 'week',
> ).annotate(
>     sum=Sum('some_field'),
> )
> }}}
>
> but unfortunately this does not work across databases. I've implemented
> an `ExtractWeekYear` class with support for all databases and will submit
> a pull request shortly.

New description:

 I found myself in the need to extract the ISO year/week-numbering year (as
 specified by ISO 8601) from a date/datetime field, e.g. to group values by
 week. This is easy with PostgreSQL:

 {{{
 from django.db.models.functions import Extract, ExtractWeek

 SomeModel.objects.annotate(
     year=Extract('some_date', 'isoyear'),
     week=ExtractWeek('some_date'),
 ).values(
     'year', 'week',
 ).annotate(
     sum=Sum('some_field'),
 )
 }}}

 but unfortunately extracting the week year like this does not work across
 databases. I've implemented an `ExtractWeekYear` class with support for
 all databases and will submit a pull request shortly.

--

Comment (by Sigurd Ljødal):

 Hey felixxm, looks like you've misunderstood what I have implemented, it's
 not the `ExtractWeek` class, but a cross database solution for
 `Extract('some_date', 'isoyear')`. I've updated the description a bit to
 clarify this.

 The week-numbering year is different from the Julian year, as e.g. January
 1st, 2017 is in week 52 of 2016.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/28649#comment:4>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" 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].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/064.6fc6105cacdef288d4284b267967733d%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to