Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- AUTH_USER_MODEL refers to model '%s' that has not been installed" % settings.AUTH_USER_MODEL django.core.exceptions.ImproperlyConfigured: AUTH_USER_MODEL refers to model 'app.User' that has not been installed
- from django import forms
- from django.contrib.auth import get_user_model
- from django.contrib.auth.forms import UserCreationForm
- from django.conf import settings
- class SignUpForm(UserCreationForm):
- first_name = forms.CharField(max_length=30)
- last_name = forms.CharField(max_length=30)
- email = forms.EmailField(max_length=254)
- class Meta:
- model = get_user_model()
- fields = ('username', 'password1', 'password2', 'email')
- from django.db import models
- from django.utils import timezone
- from django.db.models.signals import post_save
- from django.dispatch import receiver
- from django.contrib.auth.models import AbstractBaseUser, BaseUserManager, PermissionsMixin
- from django.conf import settings
- class UserManager(BaseUserManager):
- def create_user(self, email, username, password, first_name, last_name):
- if not email:
- raise ValueError("enter an email")
- if not username:
- raise ValueError("enter a username")
- if not password:
- raise ValueError("enter a password")
- user = self.model(
- email = self.normalize_email(email),
- username = username, first_name = first_name, last_name = last_name)
- if user.occupation == "admin": user.is_staff = True
- user.set_password(password)
- user.save()
- return user
- def create_superuser(self, email, username, password, first_name, last_name):
- user = self.create_user(email, username, password, first_name, last_name)
- user.is_superuser = True
- user.is_staff = True
- user.save()
- return user
- class User(AbstractBaseUser, PermissionsMixin):
- email = models.EmailField(unique=False)
- username = models.CharField(max_length=25, unique=True)
- is_staff = models.BooleanField(default=False)
- is_active = models.BooleanField(default=True)
- objects = UserManager()
- USERNAME_FIELD = "username"
- REQUIRED_FIELDS = ['email', 'first_name', 'last_name']
- def __str__(self):
- return self.username
Add Comment
Please, Sign In to add comment