'Djnago superuser is not created properly?
Super user is creating when i removed one of the seeting AUTH_USER_MODEL & in models AbstractBaseUser, PermissionsMixin and added (models.Model) otherwise it is not creating the superuser..
models.py
=============
import django
from django.db import models
import django.utils.timezone
from django.conf import settings
from django.db.models.signals import post_save
from django.dispatch import receiver
from django.contrib.auth.models import PermissionsMixin
from django.contrib.auth.base_user import AbstractBaseUser
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.base_user import BaseUserManager
from rest_framework_simplejwt.tokens import RefreshToken
from django.core.validators import RegexValidator
import datetime,calendar
import uuid
class UserManager(BaseUserManager):
use_in_migrations = True
def _create_user(self, email, password, **extra_fields):
"""
Creates and saves a User with the given mobile and password.
"""
if not email:
raise ValueError('The given email must be set')
# email = self.normalize_email(email)
user = self.model(email=email, **extra_fields)
user.set_password(password)
user.save(using=self._db)
return user
def create_user(self, email, password=None, **extra_fields):
extra_fields.setdefault('is_superuser', False)
return self._create_user(email, password, **extra_fields)
def create_superuser(self, email, password, **extra_fields):
extra_fields.setdefault('is_superuser', True)
extra_fields.setdefault('is_staff', True)
if extra_fields.get('is_superuser') is not True:
raise ValueError('Superuser must have is_superuser=True.')
return self._create_user(email, password, **extra_fields)
class UserProfile(AbstractBaseUser, PermissionsMixin):
username = models.CharField(max_length=200, unique=True, null=True, blank=True)
fullname = models.CharField(_('name'), max_length=200, blank=True, null=True)
email = models.EmailField(_('email address'), blank=True, null=True)
is_verified = models.BooleanField(default=True,)
is_active = models.BooleanField(_('active'), default=True)
is_superuser = models.BooleanField(_('is_superuser'))
objects = UserManager()
some fields are shownig errors plese check in attached picture reemaing code
model.py
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
