cityTaggedItem.py 1.12 KB
Newer Older
1
from django.db import models
Florent Chehab's avatar
Florent Chehab committed
2
3
4
from backend_app.models.abstract.taggedItem import TaggedItem, TaggedItemSerializer, TaggedItemViewSet
from backend_app.models.city import City
from backend_app.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
    city = models.ForeignKey(
        City, on_delete=models.PROTECT, related_name='city_tagged_items')
12
13
14
15
16
17

    @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
31
32
33
34
35
36

    BYPASS_DICT_MODE = True

    def extend_queryset(self):
        city_id = self.kwargs['city_id']
        return self.my_model_queryset.filter(city=city_id).distinct()