I have made custom BaseUserManager to create user but I am getting error of "please correct the errors below" when I add user from django admin panel and I can't find what's going wrong.
Models.py:
class UserManager(BaseUserManager):
def create_user(self,email,password):
user = self.model(email=email)
user.set_password(password)
def create_superuser(self,email,password):
user = self.model(email=email)
user.set_password(password)
user.is_admin = True
user.is_superuser = True
user.is_staff=True
user.save(using=self._db)
class User(AbstractBaseUser,PermissionsMixin):
COMPANY='CO'
EMPLOYEE='EM'
STATUS_CHOICES=(
(COMPANY,'Company'),
(EMPLOYEE,'Employee'),
)
Status=models.CharField(max_length=2,
choices=STATUS_CHOICES,
default=EMPLOYEE)
user_image = models.CharField(max_length=100)
is_admin=models.BooleanField()
email=models.EmailField(unique=True)
is_staff=models.BooleanField(default=False)
object = UserManager()
USERNAME_FIELD='email'
REQUIRED_FIELDS = []
objects=models.Manager()
def get_short_name(self):
return self.email
Admin.py files:
class UserAdmin(UserAdmin):
list_display = ('email', 'is_admin')
list_filter = ('is_admin',)
fieldsets = (
(None, {'fields': ('email', 'password','Status','user_image','last_login')}),
('Permissions', {'fields': ('is_admin','is_staff','is_superuser','user_permissions','groups')}),
)
add_fieldsets= (
(None, {'fields': ('email', 'password','Status','user_image','last_login')}),
('Permissions', {'fields': ('is_admin','is_staff','is_superuser','user_permissions','groups')}),
)
search_fields = ('password',)
ordering = ('password',)
filter_horizontal = ()
admin.site.register(User,UserAdmin)
admin.site.register(Company)
admin.site.register(Employee)
admin.site.register(Job)
admin.site.register(AppliedJobs)
Can someone suggest what I am doing wrong? I always get the error when I add user from admin panel.I can't figure out as I am working first time on baseusermanager.
I can suggest how to try and find the problem. Usually, your
UserAdmin
will refer to forms, see below:You can find out what is causing the errors by using logging. Add the following Mixin to your
SignUpForm
andCustomUserChangeForm
:Now, either sign in or change a user and check the logs to find out what is causing the "Please correct the errors below.".