From 6e8d06572a6b193b4ac0023482b3355a6f1f462b Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Tue, 17 Jan 2006 19:27:27 +0000 Subject: [PATCH] magic-removal: Removed _pre_save(), _post_save(), _pre_delete() and _post_delete() hooks. Just subclass the save() and delete() methods now. git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2038 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/db/models/base.py | 14 +------------- docs/model-api.txt | 19 ------------------- 2 files changed, 1 insertion(+), 32 deletions(-) diff --git a/django/db/models/base.py b/django/db/models/base.py index 0c5af69bd4..12124f90f3 100644 --- a/django/db/models/base.py +++ b/django/db/models/base.py @@ -118,7 +118,7 @@ class Model(object): def _prepare(cls): # Creates some methods once self._meta has been populated. - opts = cls._meta + opts = cls._meta opts._prepare(cls) if opts.order_with_respect_to: @@ -137,9 +137,6 @@ class Model(object): _prepare = classmethod(_prepare) def save(self): - # Run any pre-save hooks. - if hasattr(self, '_pre_save'): - self._pre_save() dispatcher.send(signal=signals.pre_save, sender=self.__class__, instance=self) non_pks = [f for f in self._meta.fields if not f.primary_key] @@ -187,9 +184,6 @@ class Model(object): # Run any post-save hooks. dispatcher.send(signal=signals.pre_save, sender=self.__class__, instance=self) - if hasattr(self, '_post_save'): - self._post_save() - save.alters_data = True def __get_pk_val(self): @@ -240,9 +234,6 @@ class Model(object): # Run any pre-delete hooks. if do_delete: - if hasattr(instance, '_pre_delete'): - instance._pre_delete() - dispatcher.send(signal=signals.pre_delete, sender=cls, instance=instance) for related in cls._meta.get_all_related_many_to_many_objects(): @@ -276,9 +267,6 @@ class Model(object): dispatcher.send(signal=signals.post_delete, sender=cls, instance=instance) - if hasattr(instance, '_post_delete'): - instance._post_delete() - connection.commit() delete.alters_data = True diff --git a/docs/model-api.txt b/docs/model-api.txt index e17a68ea5c..e9e91887cd 100644 --- a/docs/model-api.txt +++ b/docs/model-api.txt @@ -1022,25 +1022,6 @@ A few object methods have special meaning: It's good practice to use ``get_absolute_url()`` in templates, instead of hard-coding your objects' URLs. -``_pre_save`` - This method is called just before an object is saved to the database. For - example, you can use it to calculate aggregate values from other fields - before the object is saved. - - See `Adding hooks before/after saving and deleting`_ for a full example. - - .. _Adding hooks before/after saving and deleting: http://www.djangoproject.com/documentation/models/save_delete_hooks/ - -``_post_save`` - This method is called just after the object is saved to the database. This - could be used to update other tables, update cached information, etc. - -``_pre_delete`` - Like ``_pre_save``, but for deletion. - -``_post_delete`` - Like ``_post_save``, but for deletion. - Module-level methods --------------------