-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(faq): add faq model admin and transation
- update package version support
- Loading branch information
Showing
8 changed files
with
396 additions
and
105 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
""" | ||
FAQ Administrators | ||
""" | ||
from django.contrib import admin | ||
|
||
from modeltranslation.admin import TabbedTranslationAdmin | ||
|
||
from sage_ticket.models import Faq, FaqCategory | ||
|
||
|
||
class FaqInline(admin.StackedInline): | ||
"""FAQ Inline""" | ||
|
||
model = Faq | ||
extra = 1 | ||
fields = ("question", "answer") | ||
|
||
|
||
@admin.register(FaqCategory) | ||
class FaqCategoryAdmin(TabbedTranslationAdmin): | ||
""" | ||
FAQ Category Admin | ||
""" | ||
|
||
admin_priority = 4 | ||
list_display = ("title", "created_at", "modified_at") | ||
list_filter = ("created_at", "modified_at") | ||
search_fields = ("title",) | ||
save_on_top = True | ||
inlines = [FaqInline] | ||
date_hierarchy = "created_at" | ||
ordering = ("-created_at",) | ||
|
||
|
||
@admin.register(Faq) | ||
class FaqAdmin(TabbedTranslationAdmin): | ||
""" | ||
FAQ Admin | ||
""" | ||
|
||
admin_priority = 5 | ||
list_display = ("question", "category", "created_at", "modified_at") | ||
list_filter = ("category", "created_at", "modified_at") | ||
search_fields = ("question", "answer", "category__title") | ||
list_select_related = ("category",) | ||
fieldsets = ( | ||
(None, {"fields": ("question", "answer", "category")}), | ||
( | ||
"Timestamps", | ||
{"fields": ("created_at", "modified_at"), "classes": ("collapse",)}, | ||
), | ||
) | ||
readonly_fields = ("created_at", "modified_at") | ||
date_hierarchy = "created_at" | ||
ordering = ("-created_at",) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
""" | ||
FAQ Model Definition | ||
""" | ||
from django.db import models | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
from sage_tools.mixins.models.base import TimeStampMixin, TitleSlugMixin | ||
|
||
|
||
class FaqCategory(TitleSlugMixin, TimeStampMixin): | ||
""" | ||
Portfolio (Gallery) category | ||
""" | ||
|
||
objects = models.Manager() | ||
|
||
class Meta: | ||
"""Meta Information""" | ||
|
||
verbose_name = _("FAQ Category") | ||
verbose_name_plural = _("FAQ Categories") | ||
|
||
def __repr__(self): | ||
return f"<FAQ Category: {self.title}>" | ||
|
||
|
||
class Faq(TimeStampMixin): | ||
""" | ||
FAQ Model. | ||
Represents a Frequently Asked Question (FAQ) entry. Each entry consists of a | ||
question and its corresponding answer. This model is useful for managing | ||
common queries that users might have, providing a quick and accessible resource | ||
for both site visitors and administrators. | ||
""" | ||
|
||
question = models.CharField( | ||
_("Question"), | ||
max_length=150, | ||
help_text=_( | ||
"Enter the FAQ question. Keep it clear and concise to aid easy understanding." | ||
), | ||
db_comment="The question of the FAQ. Limited to 80 characters.", | ||
) | ||
|
||
answer = models.TextField( | ||
_("Answer"), | ||
help_text=_( | ||
"Provide a detailed answer to the FAQ question. Aim for clarity and completeness." | ||
), | ||
db_comment="Detailed answer to the FAQ question. Limited to 180 characters.", | ||
) | ||
|
||
category = models.ForeignKey( | ||
"FaqCategory", | ||
on_delete=models.CASCADE, | ||
related_name="faqs", | ||
verbose_name=_("Category"), | ||
help_text=_("Choose the category of the faq."), | ||
db_comment="The category to which the faq belongs.", | ||
) | ||
|
||
class Meta: | ||
"""Meta Information""" | ||
|
||
verbose_name = _("FAQ") | ||
verbose_name_plural = _("FAQ") | ||
db_table_comment = "Table storing frequently asked questions and their answers for user reference." | ||
|
||
def __str__(self): | ||
"""Cast to String""" | ||
return str(self.question) | ||
|
||
def __repr__(self): | ||
"""Object Representation""" | ||
return f"<FAQ: {self.question}>" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .faq import FaqTranslationOptions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
""" | ||
FAQ Translation | ||
""" | ||
from modeltranslation.translator import TranslationOptions, register | ||
|
||
from sage_ticket.models import Faq, FaqCategory | ||
|
||
|
||
@register(Faq) | ||
class FaqTranslationOptions(TranslationOptions): | ||
""" | ||
FAQ Translation Option | ||
""" | ||
|
||
fields = ( | ||
"question", | ||
"answer", | ||
) | ||
|
||
|
||
@register(FaqCategory) | ||
class FaqCategoryTranslationOptions(TranslationOptions): | ||
""" | ||
FAQ Category Translation Option | ||
""" | ||
|
||
fields = ("title",) |