Bruno - yes, your solution is even better as it avoids a database
lookup.  Thank you!


On Oct 12, 4:06 pm, bruno desthuilliers
<[EMAIL PROTECTED]> wrote:
> On 11 oct, 02:59, zhango <[EMAIL PROTECTED]> wrote:
>
> > I'm overriding a model's save() method, and I want to detect changes
> > in values for some of the model's fields (i.e. differences between the
> > unsaved instance's values for some fields, and the values for those
> > same fields currently in the database and about to be overwritten).
> > Is it possible to do this, and if so, how?
>
> class Yadda(models.Model):
>     blah = models.CharField(max_length=32)
>
>     def __unicode__(self):
>         return u"%s" % self.blah
>
>     def __init__(self, *args, **kw):
>         print "yadda __init__", args, kw
>         super(Yadda, self).__init__(*args, **kw)
>         self._old_blah = self.blah
>
>     def save(self, **kw):
>         print "yadda save"
>         if self.blah != self._old_blah:
>             print "blah changed - was : %s - now : %s" %
> (self._old_blah, self.blah)
>         super(Yadda, self).save(**kw)
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to