diff --git a/lacommunaute/forum/models.py b/lacommunaute/forum/models.py index 3f523d303..9b591ac5c 100644 --- a/lacommunaute/forum/models.py +++ b/lacommunaute/forum/models.py @@ -48,3 +48,6 @@ def get_unanswered_topics(self): @cached_property def count_unanswered_topics(self): return self.get_unanswered_topics().count() + + def upvotes_count(self): + return self.upvotes.count() diff --git a/lacommunaute/forum/tests/tests_model.py b/lacommunaute/forum/tests/tests_model.py index d41aad6a8..1c887068f 100644 --- a/lacommunaute/forum/tests/tests_model.py +++ b/lacommunaute/forum/tests/tests_model.py @@ -5,6 +5,7 @@ from lacommunaute.forum.factories import ForumFactory from lacommunaute.forum.models import Forum from lacommunaute.forum_conversation.factories import TopicFactory +from lacommunaute.users.factories import UserFactory class ForumManagerTest(TestCase): @@ -50,3 +51,9 @@ def test_get_absolute_url(self): forum.get_absolute_url(), f"/forum/{forum.slug}-{forum.pk}/", ) + + def test_upvotes_count(self): + forum = ForumFactory() + self.assertEqual(forum.upvotes_count(), 0) + forum.upvotes.create(voter=UserFactory()) + self.assertEqual(forum.upvotes_count(), 1)