From 0455eb6ecef039e341691aee4d5816a7b98051f2 Mon Sep 17 00:00:00 2001 From: smark-1 <75799735+smark-1@users.noreply.github.com> Date: Fri, 10 May 2024 15:38:15 -0400 Subject: [PATCH] add view onsite link for admin --- faq/models.py | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/faq/models.py b/faq/models.py index 0a3d090..67f6162 100644 --- a/faq/models.py +++ b/faq/models.py @@ -38,7 +38,6 @@ def get_absolute_url(self): else: return reverse("faq:question_detail", args=(self.slug,)) - class Meta: app_label = 'faq' @@ -77,6 +76,13 @@ def save(self, *args, **kwargs): self.not_helpful = self.get_not_helpful() super().save(*args, **kwargs) + def get_absolute_url(self): + # if using categories + if "no_category" not in settings.FAQ_SETTINGS: + return reverse("faq:question_detail", args=(self.question.category.slug, self.question.slug)) + else: + return reverse("faq:question_detail", args=(self.question.slug,)) + class Category(models.Model): name = models.CharField(max_length=50, unique=True) @@ -102,6 +108,9 @@ def save(self, *args, **kwargs): self.slug = slugify(self.name, allow_unicode='allow_unicode' in settings.FAQ_SETTINGS)[:50] return super().save(*args, **kwargs) + def get_absolute_url(self): + return reverse("faq:category_detail", args=(self.slug,)) + class FAQComment(models.Model): user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, null=True) @@ -116,6 +125,13 @@ class Meta: ordering = ['question', '-post_time'] app_label = 'faq' + def get_absolute_url(self): + # if using categories + if "no_category" not in settings.FAQ_SETTINGS: + return reverse("faq:question_detail", args=(self.question.category.slug, self.question.slug)) + else: + return reverse("faq:question_detail", args=(self.question.slug,)) + class AnswerHelpful(models.Model): user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) @@ -134,6 +150,14 @@ class Meta: ordering = ['answer', 'vote'] app_label = 'faq' + def get_absolute_url(self): + # if using categories + if "no_category" not in settings.FAQ_SETTINGS: + return reverse("faq:question_detail", args=(self.answer.question.category.slug, self.answer.question.slug)) + else: + return reverse("faq:question_detail", args=(self.answer.question.slug,)) + + class QuestionHelpful(models.Model): user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) @@ -151,3 +175,10 @@ def __str__(self): class Meta: ordering = ['question', 'vote'] app_label = 'faq' + + def get_absolute_url(self): + # if using categories + if "no_category" not in settings.FAQ_SETTINGS: + return reverse("faq:question_detail", args=(self.question.category.slug, self.question.slug)) + else: + return reverse("faq:question_detail", args=(self.question.slug,))