﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
34364	Add Today to ORM db.models.functions.datetime	Matteo Vitali	nobody	"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?"	New feature	closed	Database layer (models, ORM)	dev	Normal	wontfix			Unreviewed	0	0	0	0	0	0
