Skip to content

Instantly share code, notes, and snippets.

@hanksims
Created January 11, 2012 14:59
Show Gist options
  • Save hanksims/1595055 to your computer and use it in GitHub Desktop.
Save hanksims/1595055 to your computer and use it in GitHub Desktop.
Monitoring the initial values of Django objects
class Foo(models.Model):
bar = models.CharField(max_length=50)
def __init__(self, *args, **kwargs):
self.bar_initial = self.bar
super(Foo, self).__init__(*args, **kwargs)
def save(self, *args, **kwargs):
if self.bar == self.bar_initial:
do_stuff()
else:
do_other_stuff()
super(Foo, self).save(*args, **kwargs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment