Fix updated at not set by publish/unpublish

This commit is contained in:
Gabriel Augendre 2020-08-16 18:40:02 +02:00
parent 6444cfe24b
commit cbdf506227
2 changed files with 6 additions and 10 deletions

View file

@ -48,8 +48,7 @@ class ArticleAdmin(admin.ModelAdmin):
messages.warning(request, "You're not allowed to do this.") messages.warning(request, "You're not allowed to do this.")
return return
for article in queryset: for article in queryset:
article.publish(save=False) article.publish()
Article.objects.bulk_update(queryset, ["published_at", "status"])
messages.success(request, f"{len(queryset)} articles published.") messages.success(request, f"{len(queryset)} articles published.")
publish.short_description = "Publish selected articles" publish.short_description = "Publish selected articles"
@ -59,8 +58,7 @@ class ArticleAdmin(admin.ModelAdmin):
messages.warning(request, "You're not allowed to do this.") messages.warning(request, "You're not allowed to do this.")
return return
for article in queryset: for article in queryset:
article.unpublish(save=False) article.unpublish()
Article.objects.bulk_update(queryset, ["published_at", "status"])
messages.success(request, f"{len(queryset)} articles unpublished.") messages.success(request, f"{len(queryset)} articles unpublished.")
unpublish.short_description = "Unpublish selected articles" unpublish.short_description = "Unpublish selected articles"

View file

@ -42,15 +42,13 @@ class Article(models.Model):
content = re.sub(r"(\s)#(\w+)", r"\1\#\2", content) content = re.sub(r"(\s)#(\w+)", r"\1\#\2", content)
return md.convert(content) return md.convert(content)
def publish(self, save=True): def publish(self):
if not self.published_at: if not self.published_at:
self.published_at = timezone.now() self.published_at = timezone.now()
self.status = self.PUBLISHED self.status = self.PUBLISHED
if save:
self.save() self.save()
def unpublish(self, save=True): def unpublish(self):
self.published_at = None self.published_at = None
self.status = self.DRAFT self.status = self.DRAFT
if save:
self.save() self.save()