specialty.py 888 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 9
from backend_app.models.department import Department
from backend_app.permissions.app_permissions import ReadOnly
Florent Chehab's avatar
Florent Chehab committed
10 11


12
class Specialty(BaseModel):
Florent Chehab's avatar
Florent Chehab committed
13 14 15 16 17 18
    code = models.CharField(max_length=6)
    department = models.ForeignKey(Department, on_delete=models.PROTECT)
    name = models.CharField(max_length=100)
    active = models.BooleanField()

    class Meta:
19 20
        unique_together = ("code", "department")

Florent Chehab's avatar
Florent Chehab committed
21

22
class SpecialtySerializer(BaseModelSerializer):
Florent Chehab's avatar
Florent Chehab committed
23 24
    class Meta:
        model = Specialty
25
        fields = "__all__"
Florent Chehab's avatar
Florent Chehab committed
26 27


28
class SpecialtyViewSet(BaseModelViewSet):
Florent Chehab's avatar
Florent Chehab committed
29 30
    queryset = Specialty.objects.all()  # pylint: disable=E1101
    serializer_class = SpecialtySerializer
31 32
    permission_classes = (ReadOnly,)
    end_point_route = "specialties"