country.py 722 Bytes
Newer Older
1
from django.db import models
Florent Chehab's avatar
Florent Chehab committed
2
from rest_framework import serializers, viewsets, permissions
3

Florent Chehab's avatar
Florent Chehab committed
4

5
class Country(models.Model):
6
    name = models.CharField(max_length=200)
Florent Chehab's avatar
linting    
Florent Chehab committed
7
    iso_code = models.CharField(primary_key=True, max_length=2)
Florent Chehab's avatar
Florent Chehab committed
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29


class CountrySerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = Country
        fields = ('name', 'iso_code', 'url')


class CountryViewSet(viewsets.ModelViewSet):
    """
    retrieve:
    Retourne un pays.

    list:
    Retourne une liste de pays.

    create:
    Créée un nouveau pays.
    """
    permission_classes = (permissions.DjangoModelPermissions,)
    queryset = Country.objects.all()  # noqa: E1101
    serializer_class = CountrySerializer