From cbdf506227208229c0b9463afc232278b5f41ae8 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Sun, 16 Aug 2020 18:40:02 +0200 Subject: [PATCH] Fix updated at not set by publish/unpublish --- articles/admin.py | 6 ++---- articles/models.py | 10 ++++------ 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/articles/admin.py b/articles/admin.py index 862b341..31f52c1 100644 --- a/articles/admin.py +++ b/articles/admin.py @@ -48,8 +48,7 @@ class ArticleAdmin(admin.ModelAdmin): messages.warning(request, "You're not allowed to do this.") return for article in queryset: - article.publish(save=False) - Article.objects.bulk_update(queryset, ["published_at", "status"]) + article.publish() messages.success(request, f"{len(queryset)} articles published.") publish.short_description = "Publish selected articles" @@ -59,8 +58,7 @@ class ArticleAdmin(admin.ModelAdmin): messages.warning(request, "You're not allowed to do this.") return for article in queryset: - article.unpublish(save=False) - Article.objects.bulk_update(queryset, ["published_at", "status"]) + article.unpublish() messages.success(request, f"{len(queryset)} articles unpublished.") unpublish.short_description = "Unpublish selected articles" diff --git a/articles/models.py b/articles/models.py index 3399ceb..d7ae964 100644 --- a/articles/models.py +++ b/articles/models.py @@ -42,15 +42,13 @@ class Article(models.Model): content = re.sub(r"(\s)#(\w+)", r"\1\#\2", content) return md.convert(content) - def publish(self, save=True): + def publish(self): if not self.published_at: self.published_at = timezone.now() self.status = self.PUBLISHED - if save: - self.save() + self.save() - def unpublish(self, save=True): + def unpublish(self): self.published_at = None self.status = self.DRAFT - if save: - self.save() + self.save()