cityTaggedItem.py 963 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
from backend.models.city import City
Florent Chehab's avatar
Florent Chehab committed
4
from backend.utils import get_model_config, get_viewset_permissions
5
6


Florent Chehab's avatar
Florent Chehab committed
7
class CityTaggedItem(TaggedItem):
Florent Chehab's avatar
Florent Chehab committed
8
    model_config = get_model_config("CityTaggedItem")
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:
18
        unique_together = ('city', 'tag', 'importance_level')
19
20


Florent Chehab's avatar
Florent Chehab committed
21
class CityTaggedItemSerializer(TaggedItemSerializer):
22
23
24
25
26
    class Meta:
        model = CityTaggedItem
        fields = '__all__'


Florent Chehab's avatar
Florent Chehab committed
27
class CityTaggedItemViewSet(TaggedItemViewSet):
28
    permission_classes = get_viewset_permissions("CityTaggedItemViewSet")
29
30
    queryset = CityTaggedItem.objects.all()  # pylint: disable=E1101
    serializer_class = CityTaggedItemSerializer