country.py 1.24 KB
Newer Older
Florent Chehab's avatar
Florent Chehab committed
1
2
from django.db import models
from rest_framework import serializers, permissions
3
from backend.models.tools import DictModeViewSet
Florent Chehab's avatar
Florent Chehab committed
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

# Data model based on : https://unstats.un.org/unsd/methodology/m49/overview/


class Country(models.Model):
    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)


"""
API RELATED STUFF BELLOW
"""


class CountrySerializer(serializers.ModelSerializer):

    class Meta:
        model = Country
        fields = '__all__'


class CountryViewSet(DictModeViewSet):
    permission_classes = (permissions.DjangoModelPermissions,)
    queryset = Country.objects.all()  # pylint: disable=E1101
    serializer_class = CountrySerializer