#25760: Implement DateTime to Date Expression/Transform
-------------------------------------+-------------------------------------
               Reporter:  jarshwah   |          Owner:  nobody
                   Type:  New        |         Status:  new
  feature                            |
              Component:  Database   |        Version:  master
  layer (models, ORM)                |
               Severity:  Normal     |       Keywords:  expressions
           Triage Stage:  Accepted   |      Has patch:  1
    Needs documentation:  1          |    Needs tests:  1
Patch needs improvement:  1          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 There's a bunch of date part extracts/transforms implemented, but nothing
 to transform a datetime into a date. This is a really important function
 for aggregating by date (when you have a datetime).

 The beginnings of such a transform would be:

 {{{

 class ToDate(Transform):
     function = 'DATE'  # MySQL and SQLite
     output_field = DateField()

     def as_postgresql(self, compiler, connection):
         self.template = '(%(expression)s)::date'
         return super().as_sql(compiler, connection)

     def as_oracle(self, compiler, connection):
         self.function = 'TRUNC'
         return super().as_sql(compiler, connection)
 }}}

 And that would then be registered against the DateTimeField type with the
 lookup "date". Tests and documentation would also be required.

 #25556 is moving the existing lookups.XTransform transforms to a new
 module under django.db.models.expressions.datetime. The above transform
 should be implemented in the same location.

 The name of the Transform is also interesting. I'm not committed to the
 ToDate or even Date name, because that could imply it accepts types other
 than a DateTime. There should definitely be some parsing to ensure it's
 only going to accept a datetime (either at init or resolve time).

 This ticket will be a really good introduction to working with the ORM for
 a relatively experienced django developer. It's not easy pickings/easy,
 but it's a fairly contained patch that won't touch a large surface area.

--
Ticket URL: <https://code.djangoproject.com/ticket/25760>
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 django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/051.ba95dd29781c3705d06314a19e864136%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to