Skip to content

Commit

Permalink
feat(faq): add faq model admin and transation
Browse files Browse the repository at this point in the history
- update package version support
  • Loading branch information
MohmdFo committed Dec 4, 2024
1 parent ac16497 commit 4c73c2c
Show file tree
Hide file tree
Showing 8 changed files with 396 additions and 105 deletions.
326 changes: 224 additions & 102 deletions poetry.lock

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ packages = [
]

[tool.poetry.dependencies]
python = "^3.11"
django = "^5.0.6"
django-sage-tools = "^0.2.2"
python = ">=3.10,<4.0"
django = [
{ version = ">=4.2,<5.0", python = "3.10" },
{ version = ">=4.2,<5.3", python = ">=3.10" }, # Django 4.2 and 5.x for Python 3.10+
]
django-sage-tools = "^0.3.5"
django-modeltranslation = "^0.19.11"

[tool.poetry.group.dev.dependencies]
black = "^24.4.2"
Expand Down
3 changes: 3 additions & 0 deletions sage_ticket/admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
from .comment import CommentAdmin
from .department import DepartmentAdmin
from .issue import IssueAdmin
from .faq import FaqCategoryAdmin, FaqAdmin

__all__ = [
"AttachmentAdmin",
"CommentAdmin",
"DepartmentAdmin",
"IssueAdmin",
"FaqCategoryAdmin",
"FaqAdmin",
]
55 changes: 55 additions & 0 deletions sage_ticket/admin/faq.py
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",)
3 changes: 3 additions & 0 deletions sage_ticket/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
from .comment import Comment
from .department import Department
from .issue import Issue
from .faq import Faq, FaqCategory

__all__ = [
"Attachment",
"Comment",
"Issue",
"Department",
"Faq",
"FaqCategory",
]
76 changes: 76 additions & 0 deletions sage_ticket/models/faq.py
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}>"
1 change: 1 addition & 0 deletions sage_ticket/translation/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .faq import FaqTranslationOptions
27 changes: 27 additions & 0 deletions sage_ticket/translation/faq.py
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",)

0 comments on commit 4c73c2c

Please sign in to comment.