user15446178
user15446178

Reputation:

AUTH_USER_MODEL refers to model 'users.CustomUser' that has not been installed

models.py

User = get_user_model()
class CustomUser(AbstractUser):
   sign = models.ImageField(upload_to=image_saving)
   objects = CustomUserManager()

this is my models.py I tried to add just an extra field to django User model.

setting.py

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'rest_framework.authtoken',
'rest_auth',
'django_restful_admin',
'django_jalali',

'm',
'users',
]

AUTH_USER_MODEL = 'users.CustomUser'

I've added AUTH_USER_MODEL to my setting.py. here is my installed apps.

managers.py

class CustomUserManager(BaseUserManager):
"""
Custom user model manager where email is the unique identifiers
for authentication instead of usernames.
"""
def create_user(self, email, password, **extra_fields):
    """
    Create and save a User with the given email and password.
    """
    if not email:
        raise ValueError(_('The Email must be set'))
    email = self.normalize_email(email)
    user = self.model(email=email, **extra_fields)
    user.set_password(password)
    user.save()
    return user

def create_superuser(self, email, password, **extra_fields):
    """
    Create and save a SuperUser with the given email and password.
    """
    extra_fields.setdefault('is_staff', True)
    extra_fields.setdefault('is_superuser', True)
    extra_fields.setdefault('is_active', True)

    if extra_fields.get('is_staff') is not True:
        raise ValueError(_('Superuser must have 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)

Here is my managers.py ... I want to add a sign column to my User models.

Upvotes: 0

Views: 526

Answers (1)

user15446178
user15446178

Reputation:

I solved it very simple. I just Inherited django User model and add my extra field.:)

Upvotes: 0

Related Questions