specialty.py 826 Bytes
Newer Older
Florent Chehab's avatar
Florent Chehab committed
1
2
from django.db import models
from rest_framework import serializers, viewsets, permissions
3
from backend.models.otherCore import Department
Florent Chehab's avatar
Florent Chehab committed
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26


class Specialty(models.Model):
    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.


class SpecialtySerializer(serializers.ModelSerializer):
    class Meta:
        model = Specialty
        fields = '__all__'


class SpecialtyViewSet(viewsets.ModelViewSet):
    permission_classes = (permissions.IsAdminUser,)
    queryset = Specialty.objects.all()  # pylint: disable=E1101
    serializer_class = SpecialtySerializer