#34364 closed New feature (wontfix)
Add Today to ORM db.models.functions.datetime
Reported by: | Matteo Vitali | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
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?
Change History (4)
comment:1 by , 22 months ago
Summary: | Add Today to ORM db functions datetime → Add Today to ORM db.models.functions.datetime |
---|
comment:2 by , 22 months ago
Version: | 4.1 → dev |
---|
comment:3 by , 22 months ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
comment:4 by , 22 months ago
I would consider my proposal as an improvement of an existing feature rather than a feature from scratch, but ok, I expected that proposals on changes to the ORM would undergo a more stringent filter, but no problem if the best channel for proposing any improvement is the mailing list I can try to open a discussion there, thanks.
As far as I'm aware, after implementing #28643 we don't want to add more functions to the core unless they are common and supported by all backends. The current thread is to keep Django a core framework, not providing every utility which might be useful.
If you don't agree than first start a discussion on the DevelopersMailingList, where you'll reach a wider audience and see what other think, and follow triaging guidelines with regards to wontfix tickets.