country.py 1.33 KB
Newer Older
Florent Chehab's avatar
Florent Chehab committed
1
from django.db import models
Florent Chehab's avatar
Florent Chehab committed
2
3
from backend_app.models.abstract.my_model import MyModel, MyModelSerializer, MyModelVersionnedViewSet
from backend_app.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
    name = models.CharField(max_length=200)
    iso_alpha2_code = models.CharField(primary_key=True, max_length=2)
    iso_alpha3_code = models.CharField(
13
        unique=True, max_length=3, default='', blank=True)
Florent Chehab's avatar
Florent Chehab committed
14
15
    region_name = models.CharField(max_length=200)
    region_un_code = models.CharField(max_length=3)
16
17
    sub_region_name = models.CharField(max_length=200, default='', blank=True)
    sub_region_un_code = models.CharField(max_length=3, default='', blank=True)
Florent Chehab's avatar
Florent Chehab committed
18
    intermediate_region_name = models.CharField(
19
        max_length=200, default='', blank=True)
Florent Chehab's avatar
Florent Chehab committed
20
    intermediate_region_un_code = models.CharField(
21
        max_length=3, default='', blank=True)
Florent Chehab's avatar
Florent Chehab committed
22
23


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