cityTaggedItem.py 872 Bytes
Newer Older
1
2
3
from django.db import models
from backend.models.module import BasicModule, BasicModuleSerializer, BasicModuleViewSet
from backend.models.location import City
Florent Chehab's avatar
Florent Chehab committed
4
from backend.models.tag import Tag
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


class CityTaggedItem(BasicModule):
    city = models.OneToOneField(
        City, on_delete=models.PROTECT, related_name='city_items', primary_key=True)
    tag = models.ForeignKey(Tag, related_name='+', on_delete=models.PROTECT)

    @classmethod
    def get_serializer(cls):
        return CityTaggedItemSerializer

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


class CityTaggedItemSerializer(BasicModuleSerializer):
    class Meta:
        model = CityTaggedItem
        fields = '__all__'


class CityTaggedItemViewSet(BasicModuleViewSet):

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