Fix updated at not set by publish/unpublish
This commit is contained in:
parent
6444cfe24b
commit
cbdf506227
2 changed files with 6 additions and 10 deletions
|
@ -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"
|
||||
|
|
|
@ -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()
|
||||
|
|
Reference in a new issue