specialty.py 965 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.models.other_core import Department
3
from backend.models.abstract.my_model import MyModel, MyModelSerializer, MyModelViewSet
Florent Chehab's avatar
Florent Chehab committed
4
from backend.utils import get_model_config, get_viewset_permissions
Florent Chehab's avatar
Florent Chehab committed
5 6


7
class Specialty(MyModel):
Florent Chehab's avatar
Florent Chehab committed
8
    model_config = get_model_config("Specialty")
Florent Chehab's avatar
Florent Chehab committed
9 10 11 12 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:
        unique_together = ('code', 'department')
    # TODO add documentation : you should add departement.


19
class SpecialtySerializer(MyModelSerializer):
Florent Chehab's avatar
Florent Chehab committed
20 21 22 23 24
    class Meta:
        model = Specialty
        fields = '__all__'


25
class SpecialtyViewSet(MyModelViewSet):
26
    permission_classes = get_viewset_permissions("SpecialtyViewSet")
Florent Chehab's avatar
Florent Chehab committed
27 28
    queryset = Specialty.objects.all()  # pylint: disable=E1101
    serializer_class = SpecialtySerializer