cityTaggedItem.py 751 Bytes
Newer Older
1
from django.db import models
Florent Chehab's avatar
Florent Chehab committed
2
from backend.models.tag import TaggedItem, TaggedItemSerializer, TaggedItemViewSet
3
4
5
from backend.models.location import City


Florent Chehab's avatar
Florent Chehab committed
6
class CityTaggedItem(TaggedItem):
7
8
9
10
11
12
13
14
15
16
17
    city = models.OneToOneField(
        City, on_delete=models.PROTECT, related_name='city_items', primary_key=True)

    @classmethod
    def get_serializer(cls):
        return CityTaggedItemSerializer

    class Meta:
        unique_together = ('city', 'tag')


Florent Chehab's avatar
Florent Chehab committed
18
class CityTaggedItemSerializer(TaggedItemSerializer):
19
20
21
22
23
    class Meta:
        model = CityTaggedItem
        fields = '__all__'


Florent Chehab's avatar
Florent Chehab committed
24
class CityTaggedItemViewSet(TaggedItemViewSet):
25
26
27

    queryset = CityTaggedItem.objects.all()  # pylint: disable=E1101
    serializer_class = CityTaggedItemSerializer