specialty.py 995 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
23
    # TODO add documentation : you should add departement.


24
class SpecialtySerializer(MyModelSerializer):
Florent Chehab's avatar
Florent Chehab committed
25
26
    class Meta:
        model = Specialty
27
        fields = "__all__"
Florent Chehab's avatar
Florent Chehab committed
28
29


30
class SpecialtyViewSet(MyModelViewSet):
31
    permission_classes = get_viewset_permissions("SpecialtyViewSet")
Florent Chehab's avatar
Florent Chehab committed
32
33
    queryset = Specialty.objects.all()  # pylint: disable=E1101
    serializer_class = SpecialtySerializer