specialty.py 935 Bytes
Newer Older
Florent Chehab's avatar
Florent Chehab committed
1
from django.db import models
Florent Chehab's avatar
Florent Chehab committed
2
from backend_app.models.other_core import Department
3
4
5
6
7
from backend_app.models.abstract.my_model import (
    MyModel,
    MyModelSerializer,
    MyModelViewSet,
)
Florent Chehab's avatar
Florent Chehab committed
8
from backend_app.utils import get_model_config, get_viewset_permissions
Florent Chehab's avatar
Florent Chehab committed
9
10


11
class Specialty(MyModel):
Florent Chehab's avatar
Florent Chehab committed
12
    model_config = get_model_config("Specialty")
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(MyModelSerializer):
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(MyModelViewSet):
29
    permission_classes = get_viewset_permissions("SpecialtyViewSet")
Florent Chehab's avatar
Florent Chehab committed
30
31
    queryset = Specialty.objects.all()  # pylint: disable=E1101
    serializer_class = SpecialtySerializer