#25774: Refactor of datetime expressions and better, official support for right-
hand-side date part extraction
-------------------------------------+-------------------------------------
     Reporter:  ryuusenshi           |                    Owner:  nobody
         Type:  New feature          |                   Status:  new
    Component:  Database layer       |                  Version:  master
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:
  db,expressions,date,time,extract,transform|  Unreviewed
    Has patch:  1                    |      Needs documentation:  1
  Needs tests:  1                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by ryuusenshi):

 * needs_docs:   => 1
 * needs_tests:   => 1
 * needs_better_patch:   => 0


Old description:

> As previously stated in [https://code.djangoproject.com/ticket/25556 this
> ticket] and [https://groups.google.com/forum/#!topic/django-
> developers/GU8OrPUMjrc this thread], I have begun work on the following:
>
>    - making the so called datetime transforms (currently residing in
> `django.db.models.lookups`) part of the officially supported ORM API as
> part of the db expressions,
>    - making these transforms easily usable on the right hand side of
> lookups / Q objects
> [[BR]]
>

> To this effect, I propose the following:
>      - replace module `django.db.models.expressions` with a package of
> the same name
>      - add module `django.db.models.expressions.datetimes`
>      - rename `XTransform` to `XExtract` and move them from
> `django.db.models.lookups` to `django.db.models.lookups` to
> `django.db.models.expressions.datetimes`
>      - change `YearLookup` and `YearComparisonLookup` to allow for
> functions on the right hand side
>     - extensive testing of these db expressions
>     - adding this to the release notes
>     - any other change that might support this
>
> [[BR]]
>
> I'm also adding a [PR] with some of these already implemented. What
> remains to be done is:
>     - replace references `XTransform` type classes in
> `django.db.models.lookups` with `XExtract` classes from
> `django.db.models.expressions.datetimes`
>     - replace these references anywhere else in the project (I've noticed
> there are some in the tests, for instance)
>
> [[BR]]
>
> With the API in the [PR] it becomes possible to do the following lookup:
>

> {{{
> from django.db.models.expressions.datetimes import DateExtract
>
> Person.objects.filter(birth_date__year=DateExtract('job__start_date',
> lookup_name='year'))
> }}}
>
> which is equivalent to:
>

> {{{
> from django.db.models.expressions.datetimes import YearExtract
>
> Person.objects.filter(birth_date__year=YearExtract('job__start_date'))
> }}}
>

> Additionally, @jarshwah suggested that these should maybe be named:
> `ExtractX` instead of `XExtract`.

New description:

 As previously stated in [https://code.djangoproject.com/ticket/25556 this
 ticket] and [https://groups.google.com/forum/#!topic/django-
 developers/GU8OrPUMjrc this thread], I have begun work on the following:

    - making the so called datetime transforms (currently residing in
 `django.db.models.lookups`) part of the officially supported ORM API as
 part of the db expressions,
    - making these transforms easily usable on the right hand side of
 lookups / Q objects
 [[BR]]


 To this effect, I propose the following:
      - replace module `django.db.models.expressions` with a package of the
 same name
      - add module `django.db.models.expressions.datetimes`
      - rename `XTransform` to `XExtract` and move them from
 `django.db.models.lookups` to `django.db.models.lookups` to
 `django.db.models.expressions.datetimes`
      - change `YearLookup` and `YearComparisonLookup` to allow for
 functions on the right hand side
     - extensive testing of these db expressions
     - adding this to the release notes
     - any other change that might support this

 [[BR]]

 I'm also adding a [https://github.com/django/django/pull/5683 PR] with
 some of these already implemented. What remains to be done is:
     - replace references `XTransform` type classes in
 `django.db.models.lookups` with `XExtract` classes from
 `django.db.models.expressions.datetimes`
     - replace these references anywhere else in the project (I've noticed
 there are some in the tests, for instance)

 [[BR]]

 With the API in the [https://github.com/django/django/pull/5683 PR] it
 becomes possible to do the following lookup:


 {{{
 from django.db.models.expressions.datetimes import DateExtract

 Person.objects.filter(birth_date__year=DateExtract('job__start_date',
 lookup_name='year'))
 }}}

 which is equivalent to:


 {{{
 from django.db.models.expressions.datetimes import YearExtract

 Person.objects.filter(birth_date__year=YearExtract('job__start_date'))
 }}}


 Additionally, @jarshwah suggested that these should maybe be named:
 `ExtractX` instead of `XExtract`.

--

--
Ticket URL: <https://code.djangoproject.com/ticket/25774#comment:1>
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/068.ac6d8457ec653172bfc8ac236aace99b%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to