tag.py 732 Bytes
Newer Older
Florent Chehab's avatar
Florent Chehab committed
1
from django.db import models
2 3

from backend_app.fields import JSONField
4 5 6 7
from backend_app.models.abstract.base import (
    BaseModel,
    BaseModelSerializer,
    BaseModelViewSet,
8
)
9
from backend_app.permissions.app_permissions import ReadOnly
Florent Chehab's avatar
Florent Chehab committed
10 11


12
class Tag(BaseModel):
Florent Chehab's avatar
Florent Chehab committed
13
    """
Florent Chehab's avatar
Florent Chehab committed
14
    Model to store available "tags" in the app.
Florent Chehab's avatar
Florent Chehab committed
15
    """
16

Florent Chehab's avatar
Florent Chehab committed
17
    name = models.CharField(max_length=100, unique=True)
Florent Chehab's avatar
Florent Chehab committed
18
    config = JSONField(default=dict)
Florent Chehab's avatar
Florent Chehab committed
19 20


21
class TagSerializer(BaseModelSerializer):
Florent Chehab's avatar
Florent Chehab committed
22 23
    class Meta:
        model = Tag
24
        fields = "__all__"
Florent Chehab's avatar
Florent Chehab committed
25 26


27
class TagViewSet(BaseModelViewSet):
Florent Chehab's avatar
Florent Chehab committed
28 29
    queryset = Tag.objects.all()  # pylint: disable=E1101
    serializer_class = TagSerializer
30 31
    permission_classes = (ReadOnly,)
    end_point_route = "tags"