On Jan 2, 2011, at 2:56 PM, Carey Gagnon wrote:

> Given the following in my bizobj file:
> 
> self.DefaultValues = {"datecreated": datetime.date.today()}
> 
> will this value automatically be added to a new saved record even if the
> field is not include in the data entry form?

        Yes; it doesn't need to be displayed to take effect.

        One thing, though, is wrong with that code: it will set the value for 
that field in new records to the date that the app was started, not the date 
that the record was created. With dates that will almost always be correct, but 
if your app is running for several days or even overnight, every new record 
will get the same value. A more common case, and one that better illustrates 
the difference, would be if you wanted a timestamp for when the record was 
created. If you had:

self.DefaultValues = {"datecreated": datetime.datetime.now()}

...that would call the now() function at the time the bizobj is loaded, and 
that particular datetime value will be given to all new records. Instead, you 
should set the value part of DefaultValues to the function itself:

self.DefaultValues = {"datecreated": datetime.datetime.now}

Note the lack of parentheses after the function; that means that the default 
value is the function, and it will be called for each new record as they are 
created.



-- Ed Leafe



_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users
Searchable Archives: http://leafe.com/archives/search/dabo-users
This message: 
http://leafe.com/archives/byMID/[email protected]

Reply via email to