Opened 11 years ago

Closed 10 years ago

Last modified 10 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: UI/UX:


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


Change History (3)

comment:1 Changed 11 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:

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 11 years ago by Adrian Holovaty

Oooh, I like it!

comment:3 Changed 10 years ago by Adrian Holovaty

Resolution: fixed
Status: newclosed

This was fixed at some point a while ago.

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