Code

Opened 9 years ago

Closed 8 years ago

Last modified 8 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

Attachments (0)

Change History (3)

comment:1 Changed 9 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 9 years ago by adrian

Oooh, I like it!

comment:3 Changed 8 years ago by adrian

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

This was fixed at some point a while ago.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.