diff --git a/lacommunaute/forum/models.py b/lacommunaute/forum/models.py index 9a4b333d8..147155eb7 100644 --- a/lacommunaute/forum/models.py +++ b/lacommunaute/forum/models.py @@ -2,6 +2,7 @@ from django.contrib.auth.models import Group from django.db import models +from django.urls import reverse from django.utils.functional import cached_property from machina.apps.forum.abstract_models import AbstractForum @@ -28,6 +29,15 @@ class Forum(AbstractForum): objects = ForumQuerySet().as_manager() + def get_absolute_url(self): + return reverse( + "forum_extension:forum", + kwargs={ + "pk": self.pk, + "slug": self.slug, + }, + ) + def get_unanswered_topics(self): return Topic.objects.unanswered().filter(forum__in=self.get_descendants(include_self=True)) diff --git a/lacommunaute/forum/tests/tests_model.py b/lacommunaute/forum/tests/tests_model.py index 82b80eb0c..d41aad6a8 100644 --- a/lacommunaute/forum/tests/tests_model.py +++ b/lacommunaute/forum/tests/tests_model.py @@ -43,3 +43,10 @@ def test_kind(self): Forum.kind.field.flatchoices, [("PUBLIC_FORUM", "Espace public"), ("PRIVATE_FORUM", "Espace privé"), ("NEWS", "Actualités")], ) + + def test_get_absolute_url(self): + forum = ForumFactory() + self.assertEqual( + forum.get_absolute_url(), + f"/forum/{forum.slug}-{forum.pk}/", + )