country.py 1.32 KB
Newer Older
Florent Chehab's avatar
Florent Chehab committed
1
from django.db import models
2
from backend.models.abstract.my_model import MyModel, MyModelSerializer, MyModelVersionnedViewSet
Florent Chehab's avatar
Florent Chehab committed
3
from backend.utils import get_model_config, get_viewset_permissions
Florent Chehab's avatar
Florent Chehab committed
4 5 6
# Data model based on : https://unstats.un.org/unsd/methodology/m49/overview/


7
class Country(MyModel):
Florent Chehab's avatar
Florent Chehab committed
8
    model_config = get_model_config("Country")
9

Florent Chehab's avatar
Florent Chehab committed
10 11 12 13 14 15 16 17 18 19 20 21 22 23
    name = models.CharField(max_length=200)
    iso_alpha2_code = models.CharField(primary_key=True, max_length=2)
    iso_alpha3_code = models.CharField(
        unique=True, max_length=3, blank=False, null=False)
    region_name = models.CharField(max_length=200)
    region_un_code = models.CharField(max_length=3)
    sub_region_name = models.CharField(max_length=200, null=True, blank=True)
    sub_region_un_code = models.CharField(max_length=3, null=True, blank=True)
    intermediate_region_name = models.CharField(
        max_length=200, null=True, blank=True)
    intermediate_region_un_code = models.CharField(
        max_length=3, null=True, blank=True)


24
class CountrySerializer(MyModelSerializer):
Florent Chehab's avatar
Florent Chehab committed
25 26 27 28 29 30

    class Meta:
        model = Country
        fields = '__all__'


31
class CountryViewSet(MyModelVersionnedViewSet):
32
    permission_classes = get_viewset_permissions("CountryViewSet")
Florent Chehab's avatar
Florent Chehab committed
33 34
    queryset = Country.objects.all()  # pylint: disable=E1101
    serializer_class = CountrySerializer