I have problem with serializers for user.
models :
from django.db import models
from django.contrib.auth.models import AbstractBaseUser
class User(AbstractBaseUser):
- email = models.EmailField(unique=True)*
-
-
- USERNAME_FIELD = “email”*
- REQUIRED_FIELDS = [“username”]*
-
- def str(self):*
-
return self.email*
serializers :
views:
from rest_framework import generics
from rest_framework.response import Response
from .serializer import RegisterSerializer, UserSerializer
from rest_framework_simplejwt.tokens import AccessToken, RefreshToken
from django.contrib.auth.models import update_last_login
class RegisterApi(generics.GenericAPIView):
-
serializer_class = RegisterSerializer*
-
def post(self, request, *args, *kwargs):
-
serializer = self.get_serializer(data=request.data)*
-
serializer.is_valid(raise_exception=True)*
-
user = serializer.save()*
-
refresh_token = RefreshToken().for_user(user)*
-
token_access = AccessToken().for_user(user)*
-
update_last_login(None, user)*
-
return Response({*
-
'user': UserSerializer(user).data,*
-
'refresh': str(refresh_token),*
-
'access': str(token_access),*
-
})*