[Django] #25760: Implement DateTime to Date Expression/Transform

11 views
Skip to first unread message

Django

unread,
Nov 16, 2015, 12:59:41 AM11/16/15
to django-...@googlegroups.com
#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.

Django

unread,
Mar 5, 2016, 1:39:38 AM3/5/16
to django-...@googlegroups.com
#25760: Implement DateTime to Date Expression/Transform
-------------------------------------+-------------------------------------
Reporter: jarshwah | Owner: nobody
Type: New feature | Status: closed
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution: duplicate

Keywords: expressions | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by jarshwah):

* status: new => closed
* resolution: => duplicate


Comment:

This was already implemented for Django 1.9 in #9596 (
44f3ee77166bd5c0e8a4604f2d96015268dce100 ).

--
Ticket URL: <https://code.djangoproject.com/ticket/25760#comment:1>

Reply all
Reply to author
Forward
0 new messages