tag.py 775 Bytes
Newer Older
Florent Chehab's avatar
Florent Chehab committed
1
from django.db import models
2 3 4 5 6
from backend_app.models.abstract.my_model import (
    MyModel,
    MyModelSerializer,
    MyModelViewSet,
)
Florent Chehab's avatar
Florent Chehab committed
7 8
from backend_app.fields import JSONField
from backend_app.utils import get_viewset_permissions, get_model_config
Florent Chehab's avatar
Florent Chehab committed
9 10 11 12


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

16
    model_config = get_model_config("Tag")
17

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


class TagSerializer(MyModelSerializer):
    class Meta:
        model = Tag
25
        fields = "__all__"
Florent Chehab's avatar
Florent Chehab committed
26 27 28


class TagViewSet(MyModelViewSet):
29
    permission_classes = get_viewset_permissions("TagViewSet")
Florent Chehab's avatar
Florent Chehab committed
30 31
    queryset = Tag.objects.all()  # pylint: disable=E1101
    serializer_class = TagSerializer