User registration.

Create a new serializer in the backend/account/serializers/registration.py.

Create a new endpoint in the backend/account/views/registration.py

admin

from rest_framework import serializers
from account.models import UserProfile

class RegistrationRequestSerializer(serializers.Serializer):
    username = serializers.CharField()
    password = serializers.CharField()
    birthday = serializers.CharField() # when I used DataField I coud not override the validator
    gender = serializers.ChoiceField(choices=['male','female'])

    def validate_username(self, value):
        """
        Check that the name is unique.
        """
        error = False
        try:
            UserProfile.objects.get(username=value)
            error = True
        except:
            pass

        if error:
            raise serializers.ValidationError("This username is already exists!!!")
        return value

    def validate_birthday(self, value):
        """
        convert 2020-06-16T21:00:00.000Z -> 2020-06-16
        """
        return value.split('T')[0]


    def save(self):
        profile = UserProfile()
        profile.username = self.validated_data['username']
        profile.password = self.validated_data['password']
        profile.birthday = self.validated_data['birthday']
        profile.gender = self.validated_data['gender']
        profile.save()
        return profile
from rest_framework.views import APIView
from rest_framework.permissions import AllowAny, IsAuthenticated
from rest_framework.response import Response
from drf_yasg.utils import swagger_auto_schema
from account.serializers.registration import RegistrationRequestSerializer


class RegistrationView(APIView):
    '''

    User registration.

    __________________

    '''

    permission_classes = (AllowAny,)
    @swagger_auto_schema( 
        request_body = RegistrationRequestSerializer, \
        responses={200: RegistrationRequestSerializer} \
        )
    def post(self, request, format=None):
        obj = RegistrationRequestSerializer(data=request.data)
        obj.is_valid(raise_exception=True)
        profile = obj.save()
        return Response({'message': 'User %s has been created' % profile.username})
admin

Angular Material, Flex layout. Template-driven forms.

Make a new component in the core library.

Installation.

Add flex layout lib into

admin

admin

ng g c forms/registration-form --project=core
ng add @angular/material
admin
Потратить 2 кредита и начать обучение!
Задать вопрос, прокомментировать.