diff --git a/articles/admin.py b/articles/admin.py index 4ddac26..134115d 100644 --- a/articles/admin.py +++ b/articles/admin.py @@ -29,8 +29,9 @@ class ArticleAdmin(admin.ModelAdmin): { "fields": ( ("title", "slug"), - ("author", "status"), - ("published_at", "created_at", "updated_at"), + ("author", "comments_allowed"), + ("status", "published_at"), + ("created_at", "updated_at"), "views_count", ) }, diff --git a/articles/migrations/0019_article_comments_allowed.py b/articles/migrations/0019_article_comments_allowed.py new file mode 100644 index 0000000..9f3995a --- /dev/null +++ b/articles/migrations/0019_article_comments_allowed.py @@ -0,0 +1,18 @@ +# Generated by Django 3.1 on 2020-09-03 19:16 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("articles", "0018_auto_20200821_1232"), + ] + + operations = [ + migrations.AddField( + model_name="article", + name="comments_allowed", + field=models.BooleanField(default=True), + ), + ] diff --git a/articles/models.py b/articles/models.py index 065eddf..d3d1261 100644 --- a/articles/models.py +++ b/articles/models.py @@ -48,6 +48,7 @@ class Article(AdminUrlMixin, models.Model): author = models.ForeignKey(User, on_delete=models.PROTECT, default=1) views_count = models.IntegerField(default=0) slug = models.SlugField(unique=True, max_length=255) + comments_allowed = models.BooleanField(default=True) objects = ArticleManager() with_pages = models.Manager() diff --git a/articles/templates/articles/article_detail.html b/articles/templates/articles/article_detail.html index 18956d4..78477c4 100644 --- a/articles/templates/articles/article_detail.html +++ b/articles/templates/articles/article_detail.html @@ -11,5 +11,7 @@ {{ article.get_formatted_content|safe }} - {% include 'articles/comment_snippet.html' %} + {% if article.comments_allowed %} + {% include 'articles/comment_snippet.html' %} + {% endif %} {% endblock %} diff --git a/articles/templates/articles/comment_snippet.html b/articles/templates/articles/comment_snippet.html index e608df6..207e644 100644 --- a/articles/templates/articles/comment_snippet.html +++ b/articles/templates/articles/comment_snippet.html @@ -15,7 +15,9 @@
{% empty %} - No reaction yet, write your own! ++ No reaction yet, write your own! +
{% endfor %}