-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
49 changed files
with
1,222 additions
and
47 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
Empty file.
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,38 @@ | ||
from django.contrib import admin | ||
|
||
from modeltranslation.admin import TranslationAdmin | ||
from .models import Category, Topic | ||
|
||
|
||
@admin.register(Category) | ||
class CategoryAdmin(TranslationAdmin): | ||
save_on_top = True | ||
list_display = [ | ||
"__str__", | ||
"priority", | ||
] | ||
search_fields = [ | ||
"name", | ||
] | ||
list_editable = [ | ||
"priority", | ||
] | ||
|
||
|
||
@admin.register(Topic) | ||
class TopicAdmin(TranslationAdmin): | ||
save_on_top = True | ||
list_display = [ | ||
"__str__", | ||
"priority", | ||
"category", | ||
] | ||
search_fields = [ | ||
"name", | ||
] | ||
list_filter = [ | ||
"category", | ||
] | ||
list_editable = [ | ||
"priority", | ||
] |
Empty file.
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,32 @@ | ||
from rest_framework import serializers | ||
from api_extra.serializers import CTUIDModelSerializer | ||
from ..models import Category, Topic | ||
|
||
|
||
class TopicSerializer( | ||
CTUIDModelSerializer, | ||
serializers.ModelSerializer, | ||
): | ||
class Meta(CTUIDModelSerializer.Meta): | ||
model = Topic | ||
fields = CTUIDModelSerializer.Meta.fields + [ | ||
"question", | ||
"answer", | ||
] | ||
|
||
|
||
class CategorySerializer( | ||
CTUIDModelSerializer, | ||
serializers.ModelSerializer, | ||
): | ||
topics = TopicSerializer( | ||
many=True, | ||
read_only=True, | ||
) | ||
|
||
class Meta(CTUIDModelSerializer.Meta): | ||
model = Category | ||
fields = CTUIDModelSerializer.Meta.fields + [ | ||
"name", | ||
"topics", | ||
] |
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,11 @@ | ||
from django.urls import include, path | ||
from rest_framework import routers | ||
from . import views | ||
|
||
router = routers.DefaultRouter() | ||
router.register("categories", views.CategoryViewSet) | ||
|
||
app_name = "faq" | ||
urlpatterns = [ | ||
path("", include(router.urls)), | ||
] |
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,17 @@ | ||
from rest_framework import mixins, viewsets | ||
from . import serializers | ||
from ..models import Category, Topic | ||
|
||
|
||
class CategoryViewSet( | ||
mixins.ListModelMixin, | ||
viewsets.GenericViewSet, | ||
): | ||
queryset = Category.objects.all() | ||
serializer_class = serializers.CategorySerializer | ||
|
||
def get_queryset(self): | ||
# qs = self.queryset.prefetch_related( | ||
# 'translations', | ||
# ) | ||
return self.queryset |
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,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class FaqConfig(AppConfig): | ||
default_auto_field = "django.db.models.BigAutoField" | ||
name = "faq" |
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,103 @@ | ||
# Generated by Django 3.2.15 on 2022-10-27 12:23 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import uuid | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="Category", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("created", models.DateTimeField(auto_now_add=True, db_index=True)), | ||
("updated", models.DateTimeField(auto_now=True, db_index=True)), | ||
( | ||
"uuid", | ||
models.UUIDField(db_index=True, default=uuid.uuid4, editable=False), | ||
), | ||
( | ||
"uid", | ||
models.CharField( | ||
db_index=True, | ||
editable=False, | ||
max_length=8, | ||
null=True, | ||
unique=True, | ||
), | ||
), | ||
("name", models.CharField(max_length=64)), | ||
("name_en", models.CharField(max_length=64, null=True)), | ||
("name_de", models.CharField(max_length=64, null=True)), | ||
("name_fr", models.CharField(max_length=64, null=True)), | ||
("priority", models.PositiveSmallIntegerField(default=0)), | ||
], | ||
options={ | ||
"verbose_name": "Category", | ||
"ordering": ["-priority", "name"], | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name="Topic", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("created", models.DateTimeField(auto_now_add=True, db_index=True)), | ||
("updated", models.DateTimeField(auto_now=True, db_index=True)), | ||
( | ||
"uuid", | ||
models.UUIDField(db_index=True, default=uuid.uuid4, editable=False), | ||
), | ||
( | ||
"uid", | ||
models.CharField( | ||
db_index=True, | ||
editable=False, | ||
max_length=8, | ||
null=True, | ||
unique=True, | ||
), | ||
), | ||
("question", models.TextField(max_length=256)), | ||
("question_en", models.TextField(max_length=256, null=True)), | ||
("question_de", models.TextField(max_length=256, null=True)), | ||
("question_fr", models.TextField(max_length=256, null=True)), | ||
("answer", models.TextField()), | ||
("answer_en", models.TextField(null=True)), | ||
("answer_de", models.TextField(null=True)), | ||
("answer_fr", models.TextField(null=True)), | ||
("priority", models.PositiveSmallIntegerField(default=0)), | ||
( | ||
"category", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, to="faq.category" | ||
), | ||
), | ||
], | ||
options={ | ||
"verbose_name": "Topic", | ||
"ordering": ["category", "-priority", "question"], | ||
}, | ||
), | ||
] |
Empty file.
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,58 @@ | ||
from django.db import models | ||
from base.models.mixins import TimestampedModelMixin, CTUIDModelMixin | ||
|
||
|
||
class Category( | ||
CTUIDModelMixin, | ||
TimestampedModelMixin, | ||
models.Model, | ||
): | ||
name = models.CharField( | ||
max_length=64, | ||
) | ||
priority = models.PositiveSmallIntegerField( | ||
default=0, | ||
) | ||
|
||
class Meta: | ||
app_label = "faq" | ||
verbose_name = "Category" | ||
verbose_name_plural = "Categories" | ||
ordering = [ | ||
"-priority", | ||
"name", | ||
] | ||
|
||
def __str__(self): | ||
return self.name | ||
|
||
|
||
class Topic( | ||
CTUIDModelMixin, | ||
TimestampedModelMixin, | ||
models.Model, | ||
): | ||
question = models.TextField( | ||
max_length=256, | ||
) | ||
answer = models.TextField() | ||
priority = models.PositiveSmallIntegerField( | ||
default=0, | ||
) | ||
category = models.ForeignKey( | ||
Category, | ||
on_delete=models.CASCADE, | ||
related_name="topics", | ||
) | ||
|
||
class Meta: | ||
app_label = "faq" | ||
verbose_name = "Topic" | ||
ordering = [ | ||
"category", | ||
"-priority", | ||
"question", | ||
] | ||
|
||
def __str__(self): | ||
return 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,17 @@ | ||
from modeltranslation.translator import register, TranslationOptions | ||
from .models import Category, Topic | ||
|
||
|
||
@register(Category) | ||
class CategoryTranslationOptions(TranslationOptions): | ||
fields = [ | ||
"name", | ||
] | ||
|
||
|
||
@register(Topic) | ||
class TopicTranslationOptions(TranslationOptions): | ||
fields = [ | ||
"question", | ||
"answer", | ||
] |
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 |
---|---|---|
|
@@ -59,6 +59,7 @@ | |
"rating", | ||
"broadcast", | ||
"catalog", | ||
"faq", | ||
"redirect", | ||
"electronic_mail", | ||
"stats", | ||
|
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
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
Oops, something went wrong.