department.py 720 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.base import (
    BaseModel,
    BaseModelSerializer,
    BaseModelViewSet,
7
)
8
from backend_app.permissions.app_permissions import ReadOnly
Florent Chehab's avatar
Florent Chehab committed
9 10


11
class Department(BaseModel):
Florent Chehab's avatar
Florent Chehab committed
12 13 14 15 16
    code = models.CharField(primary_key=True, max_length=6)
    name = models.CharField(max_length=100)
    active = models.BooleanField()


17
class DepartmentSerializer(BaseModelSerializer):
Florent Chehab's avatar
Florent Chehab committed
18 19
    class Meta:
        model = Department
20
        fields = "__all__"
Florent Chehab's avatar
Florent Chehab committed
21 22


23
class DepartmentViewSet(BaseModelViewSet):
Florent Chehab's avatar
Florent Chehab committed
24 25
    queryset = Department.objects.all()  # pylint: disable=E1101
    serializer_class = DepartmentSerializer
26 27
    permission_classes = (ReadOnly,)
    end_point_route = "departments"