From 65c0846c4561130eda98d6f98d7778453960e94a Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Thu, 28 Aug 2008 19:28:17 +0000 Subject: [PATCH] Updated a few save() methods on models to accept force_insert and force_update parameters. Required as a consequence of [8670] (so they can be used with create()). git-svn-id: http://code.djangoproject.com/svn/django/trunk@8673 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/contrib/comments/models.py | 8 ++++---- django/contrib/sites/models.py | 2 +- tests/modeltests/save_delete_hooks/models.py | 5 +++-- tests/regressiontests/bug639/models.py | 4 ++-- tests/regressiontests/extra_regress/models.py | 4 ++-- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/django/contrib/comments/models.py b/django/contrib/comments/models.py index 40243d000d..e9247dd133 100644 --- a/django/contrib/comments/models.py +++ b/django/contrib/comments/models.py @@ -74,10 +74,10 @@ class Comment(BaseCommentAbstractModel): def __unicode__(self): return "%s: %s..." % (self.name, self.comment[:50]) - def save(self): + def save(self, force_insert=False, force_update=False): if self.submit_date is None: self.submit_date = datetime.datetime.now() - super(Comment, self).save() + super(Comment, self).save(force_insert, force_update) def _get_userinfo(self): """ @@ -178,7 +178,7 @@ class CommentFlag(models.Model): return "%s flag of comment ID %s by %s" % \ (self.flag, self.comment_id, self.user.username) - def save(self): + def save(self, force_insert=False, force_update=False): if self.flag_date is None: self.flag_date = datetime.datetime.now() - super(CommentFlag, self).save() + super(CommentFlag, self).save(force_insert, force_update) diff --git a/django/contrib/sites/models.py b/django/contrib/sites/models.py index c44e5ce11f..c8b395e36b 100644 --- a/django/contrib/sites/models.py +++ b/django/contrib/sites/models.py @@ -64,7 +64,7 @@ class RequestSite(object): def __unicode__(self): return self.domain - def save(self): + def save(self, force_insert=False, force_update=False): raise NotImplementedError('RequestSite cannot be saved.') def delete(self): diff --git a/tests/modeltests/save_delete_hooks/models.py b/tests/modeltests/save_delete_hooks/models.py index c1b1d8f08b..54c9defd8b 100644 --- a/tests/modeltests/save_delete_hooks/models.py +++ b/tests/modeltests/save_delete_hooks/models.py @@ -14,9 +14,10 @@ class Person(models.Model): def __unicode__(self): return u"%s %s" % (self.first_name, self.last_name) - def save(self): + def save(self, force_insert=False, force_update=False): print "Before save" - super(Person, self).save() # Call the "real" save() method + # Call the "real" save() method + super(Person, self).save(force_insert, force_update) print "After save" def delete(self): diff --git a/tests/regressiontests/bug639/models.py b/tests/regressiontests/bug639/models.py index 12f5f7b147..48fe5f8880 100644 --- a/tests/regressiontests/bug639/models.py +++ b/tests/regressiontests/bug639/models.py @@ -16,8 +16,8 @@ class Photo(models.Model): super(Photo, self).__init__(*args, **kwargs) self._savecount = 0 - def save(self): - super(Photo, self).save() + def save(self, force_insert=False, force_update=False): + super(Photo, self).save(force_insert, force_update) self._savecount += 1 class PhotoForm(ModelForm): diff --git a/tests/regressiontests/extra_regress/models.py b/tests/regressiontests/extra_regress/models.py index 500773d610..8ee06bed32 100644 --- a/tests/regressiontests/extra_regress/models.py +++ b/tests/regressiontests/extra_regress/models.py @@ -13,8 +13,8 @@ class RevisionableModel(models.Model): def __unicode__(self): return u"%s (%s, %s)" % (self.title, self.id, self.base.id) - def save(self): - super(RevisionableModel, self).save() + def save(self, force_insert=False, force_update=False): + super(RevisionableModel, self).save(force_insert, force_update) if not self.base: self.base = self super(RevisionableModel, self).save()