Opened 10 years ago

Closed 9 years ago

Last modified 9 years ago

#665 closed enhancement (fixed)

Field.default should accept callables

Reported by: adrian Owned by: adrian
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: UI/UX:

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 Changed 10 years ago by hugo

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 Changed 10 years ago by adrian

Oooh, I like it!

comment:3 Changed 9 years ago by adrian

  • Resolution set to fixed
  • Status changed from new to closed

This was fixed at some point a while ago.

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