universityPhoto.py 850 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from django.db import models
from rex.models.university import University
from rex.models.module import VersionnedModuleSerializer
from rex.models.module import Photo
from rest_framework import viewsets, permissions


class UniversityPhoto(Photo):

    university = models.OneToOneField(
        University,
        on_delete=models.CASCADE,
        related_name='university_photos')

    class Meta:
        unique_together = ('university', 'photo')


class UniversityPhotoSerializer(VersionnedModuleSerializer):

    class Meta:
        model = UniversityPhoto
        fields = '__all__'


class UniversityPhotoViewSet(viewsets.ModelViewSet):  # TODO switch to dict
    permission_classes = (permissions.DjangoModelPermissions,)
    queryset = UniversityPhoto.objects.all()  # pylint: disable=E1101
    serializer_class = UniversityPhotoSerializer