magic-removal: Changed save_delete_hooks unit test to use new convention for overriding save() and delete()

git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2037 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2006-01-17 19:18:24 +00:00
parent 6074e49daa
commit 51d2de6a56
1 changed files with 6 additions and 13 deletions

View File

@ -1,13 +1,8 @@
"""
13. Adding hooks before/after saving and deleting
Django provides hooks for executing arbitrary code around ``save()`` and
``delete()``. Just add any of the following methods to your model:
* ``_pre_save()`` is called before an object is saved.
* ``_post_save()`` is called after an object is saved.
* ``_pre_delete()`` is called before an object is deleted.
* ``_post_delete()`` is called after an object is deleted.
To execute arbitrary code around ``save()`` and ``delete()``, just subclass
the methods.
"""
from django.db import models
@ -19,16 +14,14 @@ class Person(models.Model):
def __repr__(self):
return "%s %s" % (self.first_name, self.last_name)
def _pre_save(self):
def save(self):
print "Before save"
def _post_save(self):
super(Person, self).save() # Call the "real" save() method
print "After save"
def _pre_delete(self):
def delete(self):
print "Before deletion"
def _post_delete(self):
super(Person, self).delete() # Call the "real" delete() method
print "After deletion"
API_TESTS = """