[Django] #34364: Add Today to ORM db functions datetime

2 views
Skip to first unread message

Django

unread,
Feb 22, 2023, 11:27:48 AM2/22/23
to django-...@googlegroups.com
#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.

Reply all
Reply to author
Forward
0 new messages