countryPhoto.py 824 Bytes
Newer Older
Florent Chehab's avatar
Florent Chehab committed
1
from django.db import models
2
3
4
from backend.models.location import Country
from backend.models.module import VersionnedModuleSerializer
from backend.models.module import Photo
Florent Chehab's avatar
Florent Chehab committed
5
6
7
8
9
from rest_framework import viewsets, permissions


class CountryPhoto(Photo):

10
    country = models.ForeignKey(
Florent Chehab's avatar
Florent Chehab committed
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
        Country,
        on_delete=models.CASCADE,
        related_name='country_photos')

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


class CountryPhotoSerializer(VersionnedModuleSerializer):

    class Meta:
        model = CountryPhoto
        fields = '__all__'


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