Exception Value: 'CustomUser' object is not callable | CustomUserModel

I am trying to create a custom user model. The model is working fine in command prompt and I am able to login to admin panel as well. I can access Login page as well. But when I try to access the SignUp page Is is showing me the following error.

Error image



from django.db import models
from django.contrib import auth
from django.urls import reverse
# Create your models here.

# for custom user
from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin, User
from .managers import CustomUserManager

class CustomUser(AbstractBaseUser, PermissionsMixin):
    '''Model representation for user'''
    user_type_choices = (

    account_type_choices = (
    user_type = models.CharField(max_length=5, choices=user_type_choices, default='pp', verbose_name="Who you are? ")
    account_type = models.CharField(max_length=5, choices= account_type_choices, default='o', verbose_name="Account Type ")
    email = models.EmailField(max_length=50, unique=True, blank=False, verbose_name="Your Email ")
    is_active = models.BooleanField(default=True) # anyone who signs up for thsi application is by default an active user   
    is_admin = models.BooleanField(default=False)
    is_staff = models.BooleanField(default=False)
    is_superuser = models.BooleanField(default=False) # the person who has highest level of control over database

    # need to specify manager class for this user
    objects = CustomUserManager()

    # we are not placing password field here because the password field will always be required
    REQUIRED_FIELDS = ['user_type', 'account_type']

    USERNAME_FIELD = 'email'
    EMAIL_FIELD = 'email'

# class User(User, PermissionsMixin): # for username and password

#     def __str__(self):
#         return "@{}".format(self.username)

    # def get_absolute_url(self):
    #     return reverse("Solver_detail", kwargs={"pk": self.pk})


from django.shortcuts import render
from django.urls import reverse_lazy
from . import forms
from django.views.generic import CreateView
from .managers import CustomUserManager

# Create your views here.
class SignUpView(CreateView):
    form_class = forms.SignUpForm
    success_url = reverse_lazy('login')
    template_name = 'accounts/signup.html'


from django.contrib.auth.models import BaseUserManager
# from django.contrib.auth.admin import UserAdmin as BaseUserAdmin

class CustomUserManager(BaseUserManager):
    def create_user(self, user_type, account_type, email, password):
        if not email:
            raise ValueError('User must provide valis email address')
        if not password:
            raise ValueError('User must provide password')
        user = self.model(
            user_type = user_type,
            account_type = account_type,
            email = self.normalize_email(email=email) # it normalizes the email for storage

        user.set_password(raw_password = password) # it hashes password before setting it up into the database
        user.save(using = self._db)
        return user

    def create_superuser(self, user_type, account_type, email, password):
        user = self.create_user(
            user_type= user_type,
            account_type= account_type,
            password= password
        user.is_admin = True
        user.is_staff = True
        user.is_superuser = True
        user.save(using = self._db)
        return user


# from django.contrib.auth import get_user_model
from accounts.models import CustomUser
from django.contrib.auth.forms import UserCreationForm

class SignUpForm(UserCreationForm):

    class Meta:
        fields = ('user_type','account_type','email', 'password1', 'password2')
        model = CustomUser()

    # def __init__(self, *args, **kwargs) -> None:
    #     super().__init__(*args, **kwargs)


from django.contrib import admin
from accounts.models import CustomUser

# Register your models here.

I am newbie to django developement. Please help me out.

I am expecting to know how to resolve this kind of error

your wrong in file:

class SignUpForm(UserCreationForm):

    class Meta:
        fields = ('user_type','account_type','email', 'password1', 'password2')
        model = CustomUser()

Fix to

class SignUpForm(forms.ModelForm):

    class Meta:
        fields = ('user_type','account_type','email', 'password1', 'password2')
        model = CustomUser

Because model required one MODEL, you write CustomUser() mean callable object. Model CustomUser can't do it and raise exception

Back to Top