Opened 19 years ago

Closed 18 years ago

Last modified 18 years ago

#665 closed enhancement (fixed)

Field.default should accept callables

Reported by: Adrian Holovaty Owned by: Adrian Holovaty
Component: Metasystem Version:
Severity: minor 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

Field.default should accept callables, which would be evaluated at the time that the default value was set.

Example:

default=datetime.datetime.now

Change History (3)

comment:1 by hugo, 19 years ago

how about allowing full callbacks that get passed in a self reference? That would make from your sample:

default=lambda self: datetime.datetime.now()

but would allow cool things like:

default=lambda self: self.otherfield.lower()

Sure, those could be done by _pre_save, too, but defaults kick in before validators, while _pre_save kicks in afer validators, so you often have to set blank=True to allow _pre_save to set the default on new records.

comment:2 by Adrian Holovaty, 19 years ago

Oooh, I like it!

comment:3 by Adrian Holovaty, 18 years ago

Resolution: fixed
Status: newclosed

This was fixed at some point a while ago.

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