On Dec 12, 1:02 am, "Adrian Holovaty" <[EMAIL PROTECTED]> wrote: > You can simply write a set_posted() method, like so: > > class Entry(models.Model): > post_date = models.DateTimeField(...) > posted = models.BooleanField(...) > > def set_posted(self, new_value): > if new_value != self.posted: > self.post_date = datetime.datetime.now()
Sorry if something like this post comes through twice. Google's pretty slow, but a message I sent subsquently came through and I may not have sent this. The models.Model's metaclass needs to be able to see the models.BooleanField(...) value in order to work it's magic. Setting a property subsequently overwrites that, so the model never sees "posted" at all. As a consequence, I don't see any way to avoid adding a hook to the Fields themselves to check for an override. A Getter override should receive the "default" get value and what is returned by the getter should be what is returned to the user. A Setter override should recieve what the user is trying to set, and what is returned by the override should be what is set. The only question then is whether it should work via an explicit name in the models.*Field(...) specification, i.e., "visible = models.BooleanField(setter='check_visible')", or try to pick it up automatically via convention (look for a set_visible method on the object.) I'm inclined toward the former, although it is a small change. I'm willing to go ahead and put some time into investigating this, to see if there's a relatively easy way to fix it; if I'm lucky there's some sort of universal "get" and/or "set" routines that I can just hook into. Then maybe instead of a kvetch, I'll offer a patch. (Then everybody wins. :) ) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---