countryTaggedItem.py 900 Bytes
Newer Older
1
from django.db import models
2
3
4
5
6
from backend_app.models.abstract.taggedItem import (
    TaggedItem,
    TaggedItemSerializer,
    TaggedItemViewSet,
)
Florent Chehab's avatar
Florent Chehab committed
7
from backend_app.models.country import Country
8
9


Florent Chehab's avatar
Florent Chehab committed
10
class CountryTaggedItem(TaggedItem):
11

12
    country = models.ForeignKey(
13
14
        Country, on_delete=models.PROTECT, related_name="country_tagged_items"
    )
15
16

    class Meta:
17
        unique_together = ("country", "tag", "importance_level")
18
19


Florent Chehab's avatar
Florent Chehab committed
20
class CountryTaggedItemSerializer(TaggedItemSerializer):
21
22
    class Meta:
        model = CountryTaggedItem
23
        fields = "__all__"
24
25


Florent Chehab's avatar
Florent Chehab committed
26
class CountryTaggedItemViewSet(TaggedItemViewSet):
27
28
    queryset = CountryTaggedItem.objects.all()  # pylint: disable=E1101
    serializer_class = CountryTaggedItemSerializer
29

30
    def get_queryset(self):
31
        country_id = self.kwargs["country_id"]
32
        return super().get_queryset().filter(country=country_id).distinct()