diff --git a/app/models.py b/app/models.py index a656e06d8001905f541a082a364260c1077b1f66..e9342e03f9a505c772a6b65a21dcde6175ed425a 100644 --- a/app/models.py +++ b/app/models.py @@ -99,6 +99,11 @@ class Materi(models.Model): def like_count(self): count = Like.objects.filter(materi=self).count() return count + + @property + def comment_count(self): + count = Comment.objects.filter(materi=self).count() + return count @property def is_like(self): diff --git a/app/templates/app/detail_materi.html b/app/templates/app/detail_materi.html index 577e65bfb1f077a306962335a64b9202c1b90254..8543206be10ca70cb4af7325f00aa95ce5b3d4da 100644 --- a/app/templates/app/detail_materi.html +++ b/app/templates/app/detail_materi.html @@ -268,6 +268,7 @@ {% if materi_data.status == "APPROVE" %}
+

Komentar ({{ materi_data.comment_count }})

{% if is_authenticated %}
diff --git a/app/tests.py b/app/tests.py index 653a3733f635a56a8b39fdd3906ac2b5f3a83d30..357be91468817a08ba530438068d36ea934b436c 100644 --- a/app/tests.py +++ b/app/tests.py @@ -441,6 +441,20 @@ class DetailMateriTest(TestCase): comment_like_counter = LikeComment.objects.filter(comment=comment, session_id=session_id).count() self.assertEqual(comment_like_counter, 0) + def test_detail_materi_contains_comment_count(self): + url = self.url + self.client.login(**self.contributor_credential) + + response = self.client.get(url) + self.assertContains(response, "Komentar (0)") + + self.client.post( + url, {"comment": "This is new comment by Contributor"}) + self.client.post( + url, {"comment": "This is new comment by Contributor"}) + response = self.client.get(url) + self.assertContains(response, "Komentar (2)") + def test_detail_materi_contains_form_comment(self): self.client.login(**self.contributor_credential) response = self.client.get(self.url)