countryTaggedItem.py 787 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
4
5
from backend.models.location import Country


Florent Chehab's avatar
Florent Chehab committed
6
class CountryTaggedItem(TaggedItem):
7
    country = models.OneToOneField(
Florent Chehab's avatar
Florent Chehab committed
8
        Country, on_delete=models.PROTECT, related_name='country_items', primary_key=True)
9
10
11
12
13
14
15
16
17

    @classmethod
    def get_serializer(cls):
        return CountryTaggedItemSerializer

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


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


Florent Chehab's avatar
Florent Chehab committed
24
class CountryTaggedItemViewSet(TaggedItemViewSet):
25
26
27

    queryset = CountryTaggedItem.objects.all()  # pylint: disable=E1101
    serializer_class = CountryTaggedItemSerializer