department.py 638 Bytes
Newer Older
Florent Chehab's avatar
Florent Chehab committed
1
from django.db import models
2
3
from backend.models.my_model import MyModel, MyModelSerializer, MyModelViewSet
from rest_framework import permissions
Florent Chehab's avatar
Florent Chehab committed
4
5


6
class Department(MyModel):
Florent Chehab's avatar
Florent Chehab committed
7
8
9
10
11
    code = models.CharField(primary_key=True, max_length=6)
    name = models.CharField(max_length=100)
    active = models.BooleanField()


12
class DepartmentSerializer(MyModelSerializer):
Florent Chehab's avatar
Florent Chehab committed
13
14
15
16
17
    class Meta:
        model = Department
        fields = '__all__'


18
class DepartmentViewSet(MyModelViewSet):
Florent Chehab's avatar
Florent Chehab committed
19
20
21
    permission_classes = (permissions.IsAdminUser,)
    queryset = Department.objects.all()  # pylint: disable=E1101
    serializer_class = DepartmentSerializer