On 3/29/06, Mike Kent <[EMAIL PROTECTED]> wrote: > > Here's what I'm trying to do: one of my model classes has 'date > created' and 'date updated' DateTimeCol fields. Using a > DataController, when I create a new entry, I want those two fields to > be set the same. When I update an entry, I want the 'date updated' > field set to now(). > > My first naive attempt was to do this in the model itself. I gave the > class a __setattr__ method which sets 'date updated' to now() whenever > any field in the class is set. This did not work out very well. When > I bring up the DataControllers 'add' form, enter the data, and submit, > the time it took to enter the data is now reflected in the 'date > updated' field, so 'date created' and 'date updated' are different. > Not good.
Actually, in the model seems like the correct place to do this (or in the database as triggers, but the model is the cross-database place for this). You'd want this kind of behavior picked up regardless of how you access the class. (What if you add some kind of Ajax connection to this data later? If the logic's in the controller, then these fields won't get updated from that new connection.) I vaguely remember seeing some discussion on the sqlobject list a couple months back about doing this very thing. You might want to look for that or ask on either the sqlobject or main turbogears list. Kevin --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "TurboGears Trunk" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/turbogears-trunk -~----------~----~----~----~------~----~------~--~---
