countryPhoto.py 724 Bytes
Newer Older
Florent Chehab's avatar
Florent Chehab committed
1
from django.db import models
2
from backend.models.location import Country
3
from backend.models.module import Photo, PhotoSerializer, PhotoViewSet
Florent Chehab's avatar
Florent Chehab committed
4 5 6 7


class CountryPhoto(Photo):

8
    country = models.ForeignKey(
Florent Chehab's avatar
Florent Chehab committed
9 10 11 12
        Country,
        on_delete=models.CASCADE,
        related_name='country_photos')

13 14 15 16
    @classmethod
    def get_serializer(cls):
        return CountryPhotoSerializer

Florent Chehab's avatar
Florent Chehab committed
17 18 19 20
    class Meta:
        unique_together = ('country', 'photo')


21
class CountryPhotoSerializer(PhotoSerializer):
Florent Chehab's avatar
Florent Chehab committed
22 23 24 25 26 27

    class Meta:
        model = CountryPhoto
        fields = '__all__'


28
class CountryPhotoViewSet(PhotoViewSet):
Florent Chehab's avatar
Florent Chehab committed
29 30
    queryset = CountryPhoto.objects.all()  # pylint: disable=E1101
    serializer_class = CountryPhotoSerializer