Field name `username`

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),*
    
  •    })*
    

Note, when posting code here, enclose the code between lines of three backtick - ` characters. This means you’ll have a line of ```, then your code, then another line of ```. This forces the forum software to keep your code properly formatted, which is critical with Python.

Do not markup each individual line and please do not post images of code.

Please be more specific about the issue you’re encountering. What is happening that you don’t expect to have happen, or what isn’t happening that you’re expecting to see?

If you’re getting any sort of error message, please post the complete traceback of the error. (Post the text of the message between the lines of ``` as described above.)