cityPhoto.py 691 Bytes
Newer Older
Florent Chehab's avatar
Florent Chehab committed
1
from django.db import models
2
from backend.models.location import City
3
from backend.models.module import Photo, PhotoSerializer, PhotoViewSet
Florent Chehab's avatar
Florent Chehab committed
4
5
6
7
8
9
10
11
12


class CityPhoto(Photo):

    city = models.OneToOneField(
        City,
        on_delete=models.CASCADE,
        related_name='city_photos')

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

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


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

    class Meta:
        model = CityPhoto
        fields = '__all__'


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