Rahul Sharma
Rahul Sharma

Reputation: 2495

'AbstractBaseUser' is not defined

I am trying to modify the default User model in Models.py by importing the AbstractBaseUser but I am getting the following error:

NameError: name 'AbstractBaseUser' is not defined

Models.py

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

# Create your models here.


class User(AbstractBaseUser, PermissionsMixin):

    first_name = models.CharField(max_length=15)
    last_name = models.CharField(max_length=15)
    email = models.EmailField(unique=True, max_length=254)
    mobile = models.IntegerField(unique=True)
    verified = models.BooleanField(default=False)
    date_joined = models.DateTimeField(default=timezone.now)
    is_active = models.BooleanField(default=True)
    is_admin = models.BooleanField(default=False)

Also how can I register the url of this app in my main app ?

Urls.py

urlpatterns = [
               path('create-user/', UserCreateAPIView),
               ]

Main Urls.py

urlpatterns = [
    path('admin/', admin.site.urls),
    path('api/token/', TokenObtainPairView.as_view(), name='token_obtain_pair'),
    path('api/token/refresh/', TokenRefreshView.as_view(), name='token_refresh'),
]

Upvotes: 0

Views: 1147

Answers (1)

wfehr
wfehr

Reputation: 2225

The model is called AbstractUser and you used AbstractBaseUser as a base class.

Just change it to the following:

from django.contrib.auth.models import AbstractUser


class User(AbstractUser, PermissionsMixin):

Upvotes: 1

Related Questions