Opened 9 years ago

Closed 9 years ago

#24866 closed New feature (fixed)

Add CURRENT_TIMESTAMP function to db.functions

Reported by: Curtis Maloney Owned by: Adam Johnson
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

00:21 <+jarshwah> or.. Func(template='NOW()', output_field=DateTimeFIeld()) would work too

Postgres, MySQL, SQLite and MS SQL support this function, and it would be very handy.

In the past I've implemented it using an ExpressionNode, but with the new functions module, it could be simpler and more useful.

Change History (7)

comment:1 by Josh Smeaton, 9 years ago

Triage Stage: UnreviewedAccepted
Version: 1.8master

comment:2 by Josh Smeaton, 9 years ago

Below is probably the way to go. We haven't done 0-arity Func expressions before though, so there may be some hidden traps waiting. It'd go in django.db.models.functions.py

class Now(Func):
    template = 'CURRENT_TIMESTAMP()'
    def __init__(self, output_field=DateTimeField(), **extra):
        super(Func, self).__init__(output_field=output_field, **extra)

This should (famous last words) be a relatively straight forward patch. I'd encourage someone that wants to get some basic familiarity with the ORM and expressions in general to have a go at implementing.

comment:3 by Adam Johnson, 9 years ago

Owner: changed from nobody to Adam Johnson
Status: newassigned

comment:5 by Tim Graham, 9 years ago

Has patch: set
Needs documentation: unset
Needs tests: unset

comment:6 by Tim Graham, 9 years ago

Triage Stage: AcceptedReady for checkin

comment:7 by Tim Graham <timograham@…>, 9 years ago

Resolution: fixed
Status: assignedclosed

In 23048d18:

Fixed #24866 -- Added Now() database function

Note: See TracTickets for help on using tickets.
Back to Top