#34364: Add Today to ORM db functions datetime
-------------------------------------+-------------------------------------
Reporter: Matteo | Owner: nobody
Vitali |
Type: New | Status: new
feature |
Component: Database | Version: 4.1
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Could add a function in the ORM for handling today date that uses native
templates of databases without having to go through some
`TruncDate(Now())`
I'm assuming something like this:
{{{
class Today(Func):
template = "CURRENT_DATE"
output_field = DateField()
def as_postgresql(self, compiler, connection, **extra_context):
# PostgreSQL's CURRENT_TIMESTAMP means "the time at the start of
the
# transaction". Use STATEMENT_TIMESTAMP to be cross-compatible
with
# other databases.
return self.as_sql(
compiler, connection, template="STATEMENT_TIMESTAMP()",
**extra_context
)
def as_mysql(self, compiler, connection, **extra_context):
return self.as_sql(
compiler, connection, template="CURRENT_DATE()",
**extra_context
)
def as_sqlite(self, compiler, connection, **extra_context):
return self.as_sql(
compiler,
connection,
template="STRFTIME('%%%%Y-%%%%m-%%%%d', 'NOW')",
**extra_context,
)
}}}
What do you think about?
--
Ticket URL: <https://code.djangoproject.com/ticket/34364>
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 view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/0107018679f3c647-d06e277d-fa40-4c82-8697-0a578e2d54f6-000000%40eu-central-1.amazonses.com.