code_junkie

How to prevent overwriting an object someone else has modified

Nov 13th, 2011
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.21 KB | None | 0 0
  1. def save(self):
  2. if(self.id):
  3. foo = Foo.objects.get(pk=self.id)
  4. if(foo.timestamp > self.timestamp):
  5. raise Exception, "trying to save outdated Foo"
  6. super(Foo, self).save()
Add Comment
Please, Sign In to add comment