Using the default functions for a custom User model

AttributeError: Manager isn't available; 'auth.User' has been swapped for 'application.User'

Since I changed User model, I had to do :

from django.contrib.auth import get_user_model as User

But now I get

AttributeError: 'function' object has no attribute 'objects'

for queryset = User.objects.all().order_by('-date_joined')

Had to do this :

from django.contrib.auth import get_user_model
# ...
User = get_user_model()

here you want to get all the users, so did you create a new user model in your or you are using the inbuilt django’s user model

If you’re not using Django’s built-in user model, then I suggest creating your own user model from AbstractBaseUser

class DHUserManager(BaseUserManager):
    def create_user(self, email, password=None):
        if not email:
            raise ValueError('Users must have an email address')

        user = self.model(

        return user
    def create_superuser(self, email, password=None):
        user = self.create_user(
        user.is_admin = True
        user.is_superuser = True
        user.is_staff = True
        return user

class DHUser(AbstractBaseUser):
    username = None
    email = models.EmailField(unique=True)
    is_active = models.BooleanField(default=True)
    is_admin = models.BooleanField(default=False)
    is_staff = models.BooleanField(default=False)
    is_superuser = models.BooleanField(default=False)
    created_at = models.DateTimeField(auto_now_add=True, null=True)
    updated_at = models.DateTimeField(auto_now=True, null=True)
    first_name = models.CharField(max_length=250, null=True)
    last_name = models.CharField(max_length=250, null=True)
    phone = models.CharField(max_length=250, null=True)
    company = models.CharField(max_length=250, null=True)
    city = models.CharField(max_length=250, null=True)
    zip = models.CharField(max_length=250, null=True)
    state = models.CharField(max_length=250, null=True)
    country = models.CharField(max_length=250, null=True)
    address_1 = models.CharField(max_length=250, null=True)
    address_2 = models.CharField(max_length=250, null=True)
    company_name = models.CharField(max_length=250, null=True)
    objects = DHUserManager()

    USERNAME_FIELD = 'email'
    def has_perm(self, perm, obj=None):
       return self.is_admin

    def has_module_perms(self, app_label):
       return self.is_admin
    def __str__(self):

I extended the base User model.

from django.db import models
from django.contrib.auth.models import AbstractUser, UserManager
class User(AbstractUser):
      objects = UserManager()
      dob = models.DateField(blank=True, null=True)
1 Like

I would suggest the same, if you really wants to create custom user model as per your required fields than AbstractBaseUser is good.
If you need some reference you can take a look to this Creating a Custom User Model in Django |