country.py 1.33 KB
Newer Older
Florent Chehab's avatar
Florent Chehab committed
1
from django.db import models
2
3
4
5
6
from backend_app.models.abstract.my_model import (
    MyModel,
    MyModelSerializer,
    MyModelVersionnedViewSet,
)
Florent Chehab's avatar
Florent Chehab committed
7
from backend_app.utils import get_model_config, get_viewset_permissions
8

Florent Chehab's avatar
Florent Chehab committed
9
10
11
# Data model based on : https://unstats.un.org/unsd/methodology/m49/overview/


12
class Country(MyModel):
Florent Chehab's avatar
Florent Chehab committed
13
    model_config = get_model_config("Country")
14

Florent Chehab's avatar
Florent Chehab committed
15
16
17
    name = models.CharField(max_length=200)
    iso_alpha2_code = models.CharField(primary_key=True, max_length=2)
    iso_alpha3_code = models.CharField(
18
19
        unique=True, max_length=3, default="", blank=True
    )
Florent Chehab's avatar
Florent Chehab committed
20
21
    region_name = models.CharField(max_length=200)
    region_un_code = models.CharField(max_length=3)
22
23
24
25
    sub_region_name = models.CharField(max_length=200, default="", blank=True)
    sub_region_un_code = models.CharField(max_length=3, default="", blank=True)
    intermediate_region_name = models.CharField(max_length=200, default="", blank=True)
    intermediate_region_un_code = models.CharField(max_length=3, default="", blank=True)
Florent Chehab's avatar
Florent Chehab committed
26
27


28
class CountrySerializer(MyModelSerializer):
Florent Chehab's avatar
Florent Chehab committed
29
30
    class Meta:
        model = Country
31
        fields = "__all__"
Florent Chehab's avatar
Florent Chehab committed
32
33


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