Django REST API по персонам Django REST API по персонам person api

Django REST API по персонам

Open in new window

Создаем модель и миграцию.

class Person(models.Model):
    raw_name = models.CharField(max_length=250,blank=True, null=True)
    first_name_ru = models.CharField(max_length=250,blank=True, null=True)
    last_name_ru = models.CharField(max_length=250,blank=True, null=True)
    surename_ru = models.CharField(max_length=250,blank=True, null=True)
    first_name_kz = models.CharField(max_length=250,blank=True, null=True)
    last_name_kz = models.CharField(max_length=250,blank=True, null=True)
    surename_kz = models.CharField(max_length=250,blank=True, null=True)
    first_name_lat = models.CharField(max_length=250,blank=True, null=True)
    last_name_lat = models.CharField(max_length=250,blank=True, null=True)
    surename_lat = models.CharField(max_length=250,blank=True, null=True)
    role = models.CharField(max_length=250,blank=True, null=True)

Создаем сериализатор.

class PersonSerializer(serializers.ModelSerializer):
    class Meta:
        model = Person
        fields = [  'id',
                    'raw_name',
                    'first_name_ru',
                    'last_name_ru',
                    'surename_ru',
                    'first_name_kz',
                    'last_name_kz',
                    'surename_kz',
                    'first_name_lat',
                    'last_name_lat',
                    'surename_lat',
                    'role'

                  ]

Вьюха

class PersonViewSet(viewsets.ModelViewSet):
    queryset = Person.objects.all()
    serializer_class = PersonSerializer

Роутинг

router.register(r'persons', PersonViewSet)

person form angular

Other topics