Why not simple fetch `old version` of object from database and compare its fields. For example:
def save(self, *args, **kwargs): if self._get_pk_val(): old = self.__class__.objects.get(pk=self._get_pk_val() for field in self.__class__._meta.fields: old_value = field._get_val_from_obj(old) current_value = field._get_val_from_obj(self) if old_value != current_value: #do something fun here super(self.__class__, self).save(*args, **kwargs) On Mon, Nov 10, 2008 at 22:03, Tim <[EMAIL PROTECTED]> wrote: > > Basically, I want to be able to do something if the value of a field > changes in a model. > > c = Category.objects.get(pk=1) > c.name = "New Name" > c.save() > > At any point (when the model is saved, when the value is set, etc.) is > it possible to compare the old and new value? The first thought that > popped into my head was something like this. I know this exact code > isn't possible, it's just an example of what I'm trying to do. > > class Category(models.Models): > > def save(self): > if self.name.old_value != self.name.value: > do something fun here > super(Category, self).save() > > If something like this isn't built in to Django, I was thinking of > writing a custom field and overwriting __set__() to store the old > value somewhere, since that seems to be the only place that would have > access to the new and old value. > > Any thoughts on whether that's the best method? > > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---