Skip to content

Instantly share code, notes, and snippets.

@schinckel
Created January 10, 2012 22:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schinckel/1591723 to your computer and use it in GitHub Desktop.
Save schinckel/1591723 to your computer and use it in GitHub Desktop.
class MyModel(models.Model):
...
def save(self, *args, **kwargs):
if self.pk:
old_version = self.__class__.objects.get(pk=self.pk)
# Now we have self and old_version, which are different
# instances of the same object.
if old_version.foo_field != self.foo_field:
# foo_field is changed, do stuff.
super(MyModel, self).save(*args, **kwargs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment