countryTaggedItem.py 1007 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.country import Country
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 CountryTaggedItem(TaggedItem):
Florent Chehab's avatar
Florent Chehab committed
8
    model_config = get_model_config("CountryTaggedItem")
9
    country = models.OneToOneField(
Florent Chehab's avatar
Florent Chehab committed
10
        Country, on_delete=models.PROTECT, related_name='country_items', primary_key=True)
11 12 13 14 15 16

    @classmethod
    def get_serializer(cls):
        return CountryTaggedItemSerializer

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


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


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