'login with phone number in django

I get this error when making changes

self.UserModel._default_manager.db_manager(database).create_superuser(**user_data) TypeError: create_superuser() missing 1 required positional argument: 'username'

model

from django.db import models
from django.contrib.auth.models import AbstractUser


class Userperson(AbstractUser):

    gender_choice = [
        ('M', 'male'),
        ('F', "female")
    ]
    roles = [
        ('seller', 'Seller'),
        ('shopper', 'Shopper'), 
        ('serviceman', 'Serviceman')
    ]
    fullname = models.CharField(max_length=100, verbose_name="Fullname")
    phone = models.CharField(max_length=20,verbose_name="Phone",unique=True)
    image = models.ImageField(upload_to="userphoto/fullname", blank=True, null=True, verbose_name="userPhoto")
    phone_auth = models.BooleanField(default=False)
    gender = models.CharField(choices=gender_choice, blank=False, null=False, max_length=50)
    role = models.CharField(choices=roles, max_length=50)

    # ?
    USERNAME_FIELD = 'phone'
    #REQUIRED_FIELDS = ['fullname']

admin

from django.contrib import admin
from .models import Userperson

@admin.register(Userperson)
class personadmin(admin.ModelAdmin):
    list_display = ['fullname', 'phone', 'image', 'phone_auth']

What should I do to solve the problem?



Solution 1:[1]

Userperson is a child class of AbstractUser and inherits all of methods and fields of parent class.

However AbstractUser has username field and that is required.

You should set username inside user_data dictionary when creating new user object.

Also

USERNAME_FIELD - A string describing the name of the field on the user model that is used as the unique identifier

Are you sure that you want to identify user uniqueness by phone number? number with country code +987-1234-5678 and without it 0-1234-5678 (for country internal usage) will be two different users

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1