In my last message I copied the following bizobj definition from one of my working apps, but in reading it I noticed a problem with my code. I'll take this opportunity to publicly explore the problem and hopefully we'll all learn more about the finer points of Dabo.

Paul McNett wrote:
class Payments(Base):
def initProperties(self):
        self.Caption = "Payments"
        self.DataSource = "payments"
        self.KeyField = "iid"
        self.RequeryOnLoad = False
        self.DefaultValues = {"dcheckdate": datetime.date.today()}

Note that the default value for the dcheckdate field for all new records will get set to today. Seems right, except that the today() function gets called once (at bizobj instantiation) and the default value will always be set to that value. If I leave the app open and running for a week, the default value for the check date will not actually be set to the current day.

dBizobj's DefaultValues property is a simple Python dictionary with keys on the field name and values set to the default value you want for that field. Sounds simple enough, but there's a feature easily overlooked: you can set the default value for a field to a function which will be called at the time the new record is added. The way that would be written is:

         self.DefaultValues = {"dcheckdate": datetime.date.today}

A minor syntactic difference, but the former is static and the latter dynamic and much more useful in many cases.

Anyway, I should go fix that in my code now...

--
Paul McNett
http://paulmcnett.com
http://dabodev.com


_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users

Reply via email to