From a90e9f43db394565502c040502d8a4421767ba0b Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Mon, 8 Aug 2005 18:30:07 +0000 Subject: [PATCH] Companion checkin to [432] git-svn-id: http://code.djangoproject.com/svn/django/trunk@433 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/core/meta/__init__.py | 6 ++++++ tests/testapp/models/__init__.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/django/core/meta/__init__.py b/django/core/meta/__init__.py index bcd8ad4b96..06c3aca3a6 100644 --- a/django/core/meta/__init__.py +++ b/django/core/meta/__init__.py @@ -756,6 +756,9 @@ def method_save(opts, self): def method_delete(opts, self): assert getattr(self, opts.pk.name) is not None, "%r can't be deleted because it doesn't have an ID." + # Run any pre-delete hooks. + if hasattr(self, '_pre_delete'): + self._pre_delete() cursor = db.db.cursor() for rel_opts, rel_field in opts.get_all_related_objects(): rel_opts_name = opts.get_rel_object_method_name(rel_opts, rel_field) @@ -782,6 +785,9 @@ def method_delete(opts, self): # delete it from the filesystem. if os.path.exists(file_name) and not opts.get_model_module().get_list(**{'%s__exact' % f.name: getattr(self, f.name)}): os.remove(file_name) + # Run any post-delete hooks. + if hasattr(self, '_post_delete'): + self._post_delete() def method_get_next_in_order(opts, order_field, self): if not hasattr(self, '_next_in_order_cache'): diff --git a/tests/testapp/models/__init__.py b/tests/testapp/models/__init__.py index 4ad4516718..2c81a27ef3 100644 --- a/tests/testapp/models/__init__.py +++ b/tests/testapp/models/__init__.py @@ -1,3 +1,3 @@ __all__ = ['basic', 'repr', 'custom_methods', 'many_to_one', 'many_to_many', 'ordering', 'lookup', 'get_latest', 'm2m_intermediary', 'one_to_one', - 'm2o_recursive', 'm2o_recursive2'] + 'm2o_recursive', 'm2o_recursive2', 'save_delete_hooks']