I am creating a custom user registration form and I keep getting this error. How do I correct this.
> ProgrammingError at /Identity/register/ (1146, "Table 'nest.auth_user'
> doesn't exist")
I adjusted the authentication system to use email instead of username and I switched from SQlite to Mysql.
# Create models for Identities app.
from django.db import models
from django.contrib.auth.models import AbstractUser, BaseUserManager
from django.utils.translation import ugettext_lazy as _
from django.db.models.signals import post_save
from django.contrib.auth.models import User
# Create your models here.
class UserManager(BaseUserManager):
# Create a model manager for User model with no user name field
use_in_migrations = True
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 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):
# Create and save a regular User with the given email and password.
extra_fields.setdefault('is_staff', False)
extra_fields.setdefault('is_superuser', False)
return self._create_user(email, password, **extra_fields)
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)
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)
class User(AbstractUser):
# User Model
username = None
email = models.EmailField(_('email add '), unique = True)
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = []
objects = UserManager()
I registered the User Model:
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin as DjangoUserAdmin
from django.utils.translation import ugettext_lazy as _
from .models import User
# Add User profile from models document
from Identities.models import UserProfile
# Register your models here.
#admin.register(User)
class UserAdmin(DjangoUserAdmin):
# Create administration model for custom User model
fieldsets = (
(None, {'fields': ('email', 'password')}),
(_('Personal info'), {'fields': ('first_name', 'last_name')}),
(_('Permissions'), {'fields': ('is_active', 'is_staff', 'is_superuser',
'groups', 'user_permissions')}),
(_('Important dates'), {'fields': ('last_login', 'date_joined')}),
)
add_fieldsets = (
(None, {
'classes': ('wide',),
'fields': ('email', 'password1', 'password2'),
}),
)
list_display = ('email', 'first_name', 'last_name', 'is_staff')
search_fields = ('email', 'first_name', 'last_name')
ordering = ('email',)
I also created a custom user model and registered the model
class UserProfile(models.Model):
user = models.OneToOneField(User)
contact = models.IntegerField(default=0)
admin.site.register(UserProfile)
I created the register view :
from django.shortcuts import render
from Identities.forms import CreateAccountForm
def register(request):
if request.method == 'POST':
form = CreateAccountForm(request.POST)
if form.is_valid():
form.save()
else:
return redirect(reverse('Identities:logout'))
else:
form = CreateAccountForm()
var = {'form' : form}
return render(request, 'Identities/create_account.html', var)
Then I created the class model in forms.py
from django import forms
from django.contrib.auth.models import User
from django.contrib.auth.forms import UserCreationForm
class CreateAccountForm(UserCreationForm):
email = forms.EmailField(required = True)
class Meta:
model = User
fields = (
'first_name',
'last_name',
'email',
'password1',
'password2'
)
def save(self, commit = True):
user = super(CreateAccountForm, self).save(commit = False)
user.first_name = self.cleaned_data['first_name']
user.last_name = self.cleaned_data['last_name']
user.email = self.cleaned_data['email']
if commit:
user.save()
return user
You need to migrate first
python3 manage.py makemigrations
python3 manage.py migrate
Need to migrate your model files to database...
python manage.py makemigrations
python manage.py migrate
This happened to me when switching from sqlite to mysql. I guess I'd made auth_user on sqlite and it didn't exist on mysql.
A few things seemed to really help me out.
Restarting Apache: sudo systemctl restart apache2
Making a new super user: python3 manage.py createsuperuser.
I got this error: Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
So then I did python3 manage.py makemigrations and python3 manage.py migrate for admin, auth, contenttypes, sessions.
Then again: python3 manage.py createsuperuser.
It fixed it for me.
I also had that error when I referenced my custom User-class in a separate Model via a ForeignKey for example. I set AUTH_USER_MODEL in my settings.py like this:
AUTH_USER_MODEL = "users.User"
I fixed it by using that reference from settings.AUTH_USER_MODEL instead. For this, you need to import it first:
# Replace this
# from users.models import MyUser
# With this
from django.conf import settings
and replace your custom User-model with the one from the settings:
# Replace this
# owner = models.ForeignKey(MyUser, related_name="budgets", on_delete=models.PROTECT)
# With this
owner = models.ForeignKey(settings.AUTH_USER_MODEL, related_name="budgets", on_delete=models.PROTECT)
Related
I have this in my models.py:
class UserManager(BaseUserManager):
def create_user(self, name, password=None):
"""
Creates and saves a User with the given name and password.
"""
if not name:
raise ValueError('A user must have a name.')
user = self.model()
user.set_password(password)
user.save(using=self._db)
return user
def create_staffuser(self, name, password):
"""
Creates and saves a staff user with the given name and password.
"""
user = self.create_user(
name,
password=password,
)
user.staff = True
user.save(using=self._db)
return user
def create_superuser(self, name, password, id):
"""
Creates and saves a superuser with the given name and password.
"""
user = self.create_user(
name,
id,
password=password,
)
user.staff = True
user.admin = True
user.save(using=self._db)
return user
The reason I added the field id in my create_superuser -method is that it is a required field in my model and I thought I need to include it also when running python manage.py createsuperuser. My problem is that I don't know how to customize the super user creation. With this I always get the error TypeError: create_superuser() missing 1 required positional argument: 'id'. I also tried to remove the id from the function. The process goes through without errors then, but I can't log in to the admin site, it says the username or password are not correct.
I have this in my admin.py:
from django.contrib import admin
from django.contrib.auth import get_user_model
from django.contrib.auth.models import Group
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
from .forms import UserAdminCreationForm, UserAdminChangeForm
User = get_user_model()
# Remove Group Model from admin. We're not using it.
admin.site.unregister(Group)
class UserAdmin(BaseUserAdmin):
# The forms to add and change user instances
form = UserAdminChangeForm
add_form = UserAdminCreationForm
# The fields to be used in displaying the User model.
# These override the definitions on the base UserAdmin
# that reference specific fields on auth.User.
list_display = ['name', 'admin']
list_filter = ['admin']
fieldsets = (
(None, {'fields': ('name', 'password')}),
('Personal info', {'fields': ()}),
('Permissions', {'fields': ('admin',)}),
)
# add_fieldsets is not a standard ModelAdmin attribute. UserAdmin
# overrides get_fieldsets to use this attribute when creating a user.
add_fieldsets = (
(None, {
'classes': ('wide',),
'fields': ('name', 'password1', 'password2')}
),
)
search_fields = ['name']
ordering = ['name']
filter_horizontal = ()
admin.site.register(User, UserAdmin)
Do I need to modify the admin.py -file to make this work or is there some other obvious reason why it doesn't work?
In any case, it is really bad practice to give id value manually. the id should be auto-generated. But if you really want to get id as a function parameter, then you need to override the Django command to create a superuser.
You can read the details for the custom Django admin command here.
https://docs.djangoproject.com/en/3.2/howto/custom-management-commands/
I tried to search and study some information on the google, but I couldn't find the good solution.
I have several Django projects and want to create "Member" project store user information which implement Single-Sign-On(SSO) feature (ex/"django-simple-sso"). Then I need to classify user permission, I study the package "django-guardian" which maybe can help me do object permission.
I do below things to create custom model in "Member" project. Then I just post the code that I add/change.
# setting.py of "Member" project
INSTALLED_APPS = [
'users',
'guardian'
]
AUTHENTICATION_BACKENDS = (
'guardian.backends.ObjectPermissionBackend',
)
I add an app which called users in the project named "Member".
# admin.py in the users app of Member project.
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from .forms import CustomUserCreationForm, CustomUserChangeForm
from .models import CustomUser
class CustomUserAdmin(UserAdmin):
add_form = CustomUserCreationForm
form = CustomUserChangeForm
model = CustomUser
list_display = ('email', 'is_staff', 'is_active', 'employee_account', 'location', 'chinese_name', 'english_name', 'extension', 'last_login', 'date_joined')
list_filter = ('email', 'is_staff', 'is_active', 'employee_account', 'location', 'chinese_name', 'english_name', 'extension', 'last_login', 'date_joined')
fieldsets = (
(None, {'fields': ('employee_account', 'password')}),
('Permissions', {'fields': ('is_staff', 'is_active')}),
)
add_fieldsets = (
(None, {
'classes': ('wide',),
'fields': ('employee_account', 'password1', 'password2', 'is_staff', 'is_active')}
),
)
search_fields = ('employee_account',)
ordering = ('employee_account',)
admin.site.register(CustomUser, CustomUserAdmin)
# apps.py in the users app of Member project.
from django.apps import AppConfig
class UsersConfig(AppConfig):
name = 'users'
# forms.py in the users app of Member project.
from django.contrib.auth.forms import UserCreationForm, UserChangeForm
from .models import CustomUser
class CustomUserCreationForm(UserCreationForm):
class Meta(UserCreationForm):
model = CustomUser
fields = ('employee_account',)
class CustomUserChangeForm(UserChangeForm):
class Meta:
model = CustomUser
fields = ('employee_account',)
# manager.py in the users app of Member project.
from django.contrib.auth.base_user import BaseUserManager
from django.utils.translation import ugettext_lazy as _
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)
# models.py in the users app of Member project
from django.db import models
from django.db import models
from django.contrib.auth.models import AbstractBaseUser
from django.contrib.auth.models import PermissionsMixin
from django.utils.translation import gettext_lazy as _
from django.utils import timezone
from .managers import CustomUserManager
class CustomUser(AbstractBaseUser, PermissionsMixin):
employee_account = models.CharField(max_length=100, unique=True)
location = models.CharField(max_length=50)
chinese_name = models.CharField(max_length=30)
english_name = models.CharField(max_length=30)
extension = models.CharField(max_length=30)
email = models.EmailField(max_length=125)
is_staff = models.BooleanField(default=False)
is_active = models.BooleanField(default=True)
date_joined = models.DateTimeField(default=timezone.now)
USERNAME_FIELD = 'employee_account'
REQUIRED_FIELDS = ['location','chinese_name','english_name','extension', 'email']
objects = CustomUserManager()
def __str__(self):
return self.employee_account
Then I use django shell to add user and assign permission.
>>> from django.contrib.auth.models import Group
>>> from users.models import CustomUser
>>> jack = CustomUser.objects.create_user('123456789#gamil.com', '123456789')
>>> admins = Group.objects.create(name='admins')
>>> jack.has_perm('change_group', admins)
False
>>> from guardian.models import UserObjectPermission
>>> UserObjectPermission.objects.assign_perm('change_group', jack, obj=admins)
<UserObjectPermission: admins | | change_group>
>>> jack.has_perm('change_group', admins)
True
>>> jack.has_perm('change_group')
False
After that I create an book app in another project named book_web.
# model.py in the book app of book_web project
from django.db import models
class Book(models.Model):
sn = models.CharField(max_length=200)
book = models.CharField(max_length=100)
author = models.CharField(max_length=100)
price = models.PositiveIntegerField(null=True, blank=True)
number = models.PositiveIntegerField(null=True, blank=True)
1. It seems work abnormally when key this command UserObjectPermission.objects.assign_perm('change_group', jack, obj=admins). I found that response doesn't show the user name which is different with django-guardian example code.
2. I don't know how to assign Book object permission in Member project such as django-guardian example code. Because there is not same model as Book model in the Member project.
Does anyone have similar experience about this?
If you have another recommendation package to implement the feature, welcome to share your experience. Thanks for your response.
The custom authentication I wrote follows the instructions from the docs. I am able to register, login, and logout the user, no problem there. Then, when I create a superuser python manage.py createsuperuser, it creates a user in the database, but it does not let me login when I go to the admin page and try to login saying
Please enter the correct email address and password for a staff account. Note that both fields may be case-sensitive.
Here is my code:
models.py:
from __future__ import unicode_literals
from django.db import models
from django.db import models
from django.contrib.auth.models import AbstractUser, AbstractBaseUser, Group, Permission
from django.contrib.auth.models import BaseUserManager
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import PermissionDenied, ObjectDoesNotExist, MultipleObjectsReturned
from datetime import datetime
from django.contrib.auth.models import PermissionsMixin
import re
class CustomUserManager(BaseUserManager):
def create_user(self, email, password = None):
'''Creates and saves a user with the given email and password '''
if not email:
raise ValueError('Email address is requied.')
user = self.model(email = self.normalize_email(email))
user.set_password(password)
user.save(using=self._db)
return user
def create_superuser(self, email, password):
''' Creates and saves a superuser with the given email and password '''
user = self.create_user(email, password = password)
user.is_admin = True
user.is_superuser = True
user.save(using=self._db)
return user
class User(AbstractBaseUser, PermissionsMixin):
"""
Custom user class
"""
email = models.EmailField(verbose_name = 'email address',unique = True, db_index = True)
# email is the unique field that can be used for identification purposes
first_name = models.CharField(max_length = 20)
last_name = models.CharField(max_length = 30)
joined = models.DateTimeField(auto_now_add = True)
is_active = models.BooleanField(default = True)
is_admin = models.BooleanField(default = False)
is_superuser = models.BooleanField(default = False)
group = models.ManyToManyField(Group, related_name = 'users')
permission = models.ManyToManyField(Permission, related_name = 'users')
objects = CustomUserManager()
USERNAME_FIELD = 'email' # the unique identifier (mandatory) The filed must have unique=True set in its definition (see above)
def get_full_name(self):
return self.email
def get_short_name(self):
return self.first_name
def has_perm(self, perm, obj=None):
''' Does the user have a specific permission'''
return True # This may need to be changed depending on the object we want to find permission for
def has_module_perms(self, app_label):
''' Does the user have permission to view the app 'app_label'? The default answer is yes.
This may be modified later on. '''
return True
#property
def is_staff(self):
''' IS the user a member of staff? '''
return self.is_admin
def __unicode__(self):
return '{user_email}, {user_title} joined on {joined_date}'.format(user_email = self.email,
user_title = self.user_type,
joined_date = self.joined)
In backends.py:
from django.conf import settings
from django.contrib.auth.hashers import check_password
from accounts.models import User
class EmailAuthBackend(object):
''' Custom authentication backend. Allows users to login using their email address '''
def authenticate(self, email=None, password = None):
''' the main method of the backend '''
try:
user = User.objects.get(email = email)
if user.check_password(password):
return user
except User.DoesNotExist:
return None
def get_user(self, user_id):
try:
user = User.objects.get(pk = user_id) # Note that you MUST use pk = user_id in getting the user. Otherwise, it will fail and even though the user is authenticated, the user will not be logged in
if user.is_active:
return user
return None
except User.DoesNotExist:
return None
in admin.py:
from django import forms
from django.contrib import admin
from django.contrib.auth.models import Group
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
from django.contrib.auth.forms import ReadOnlyPasswordHashField
from accounts.models import User as CustomUser
class UserCreationForm(forms.ModelForm):
''' A Form for creating new users. Includes all the required field, plus a repeated password.'''
password1 = forms.CharField(label = 'Password', widget = forms.PasswordInput)
password2 = forms.CharField(label = 'Password Confirmation', widget = forms.PasswordInput)
class Meta:
model = CustomUser
fields = ('email',)
def clean_password2(self):
''' Checks that the two password entries match '''
password1 = self.cleaned_data.get('password1')
password2 = self.cleaned_data.get('password2')
if password1 and password2 and password1 != password2:
raise forms.ValidationError('Passwords do NOT match!')
return password2
def save(self, commit = True):
''' Save the provided password in hashed format '''
user = super(UserCreationForm, self).save(commit = False)
user.set_password(self.cleaned_data['password1'])
if commit:
user.save()
return user
class UserChangeForm(forms.ModelForm):
''' A form for updating users. Includes all the field on the user, but replaces the password field with admin's password hash display field '''
password = ReadOnlyPasswordHashField()
class Meta:
model = CustomUser
fields = ('email', 'password', 'first_name', 'last_name', 'is_active', 'is_admin')
def clean_password(self):
''' Regardless of what the user provides, return the initial value. This is done here rather than on the field because the field
does not have access to the initial value'''
return self.initial['password']
class UserAdmin(BaseUserAdmin):
''' The form to add and change user instances '''
form = UserChangeForm
add_form = UserCreationForm
# The fields to be used in displaying the user model.
# These override the defintions on the base UserAdmin
# that reference specific fields on auth.User
list_display = ('email', 'first_name', 'last_name', 'is_admin')
list_filter = ('is_admin',)
fieldsets = (
(None, {'fields': ('email', 'password')}),
('Personal Info',{'fields': ('first_name', 'last_name',)}),
('Permissions', {'fields': ('is_admin',)}),
)
# add_fieldsets is not a standard ModelAdmin attribute. UserAdmin
# overrides get_fieldsets to use this attribute when creating a user
add_fieldsets = (
(None, {'classes': ('wide',),
'fields': ('email', 'first_name', 'last_name', 'password1', 'password2')}
),
)
search_fields = ('email',)
ordering = ('email',)
filter_horizontal = ()
# Now, register the new UserAdmin...
admin.site.register(CustomUser, UserAdmin)
# ... and, since we're not using Django's built-in permissions,
# unregister the Group model from admin.
admin.site.unregister(Group)
And, finally, in settings.py:
AUTHENTICATION_BACKENDS = ['accounts.backends.EmailAuthBackend',]
So what's missing?
I think the problem is in your EmailAuthBackend. If you add some printing/logging to the backend, you'll find that the login form calls the authenticate method with username and password. This means that email is None, and therefore the user = User.objects.get(email = email) lookup fails.
In your case, the regular ModelBackend will work fine for you, because you have USERNAME_FIELD = 'email'. If you remove AUTHENTICATION_BACKENDS from your settings then the login should work. You can then remove your EmailAuthBackend.
If you wanted to log in users with their cell number and password (and cell_number was not the USERNAME_FIELD, then you would need a custom authentication backend. You would also need a custom authentication form that called authenticate(cell_number=cell_number, password=password). Another example of a custom authentication backed is RemoteUserBackend, which logs in the user based on an environment variable set by the server.
Had the same issue. Instead of password=None, I changed it to password only. And passed 'password=password' , together with 'username=username' as you can see below:
class MyAccountManager(BaseUserManager):
def create_user(self, email, username, password):
if not email:
raise ValueError('Please add an email address')
if not username:
raise ValueError('Please add an username')
user = self.model(email=self.normalize_email(
email), username=username, password=password)
user.set_password(password)
user.save(using=self._db)
return user
def create_superuser(self, email, username, password):
user = self.create_user(email=self.normalize_email(
email), username=username, password=password)
And as Denis has already said above, make sure to add AUTH_USER_MODEL = 'accounts.User' to settings.py
I've created a CustomUser from AbstractUser in Django 1.9. Add on admin.sites.register when I was create superuser, django have created successful but when I was log in on system the user didn't exists.
Follow the code:
On customuser/models.py:
from __future__ import unicode_literals
from django.db import models
from django.contrib.auth.models import AbstractUser
from django.contrib.auth.models import AbstractBaseUser, BaseUserManager
class CustomUserManager(BaseUserManager):
def create_user(self, username, email, first_name, last_name, cpf, password=None):
user = self.model(
username=username,
email=email,
first_name=first_name,
last_name=last_name,
cpf=cpf
)
return user
def create_superuser(self, username, email, first_name, last_name, cpf, password):
user = self.create_user(username, email, first_name, last_name, cpf,
password=password)
user.is_super_user = True
user.save()
return user
class CustomUser(AbstractUser):
SEXO_CHOICES = (
(u'Masculino', u'Masculino'),
(u'Feminino', u'Feminino'),
)
cpf = models.BigIntegerField(unique=True)
phone = models.CharField(max_length=15, blank=True)
is_super_user = models.BooleanField(default=False)
data_de_nascimento = models.DateField(null=True)
sexo = models.CharField(max_length=9, null=True, choices=SEXO_CHOICES)
USERNAME_FIELD = 'username'
REQUIRED_FIELDS = ['email', 'first_name', 'last_name', 'cpf']
objects = CustomUserManager()
On settins.py, I add the line:
INSTALLED_APPS = [
...
'customuser',
]
...
AUTH_USER_MODEL = 'customuser.CustomUser'
And my customuser/admin.py:
from django.contrib import admin
from models import CustomUser, CustomUserManager
admin.site.register(CustomUser)
Thanks a lot for your help.
See these docs on making custom user work with admin site.
UPDATE:
Sorry, previously I thought, you were inheriting your model from AbstractBaseUser, therefore that answer was giving you error.
Since, you're inheriting from AbstractUser, your subclass will automatically get is_staff field. So, you'll just need to set is_staff to True in create_superuser method.
class CustomUserManager(...):
# ...
def create_superuser(...):
# ...
user.is_staff = True
user.save()
return user
In my current project I'm replacing the default django user model. As the number of models started growing I decided to split the implementation into several folders, but now django can't find my user model.
I had this, which works:
djutils
models.py
UserManager
User
I changed to this and it doesn't work anymore
djutils
models
__init__.py
from djutils.models.user import UserManager, User
user.py
UserManager
User
Shouldn't it still import the models? I get:
CommandError: One or more models did not validate:
auth.user: Model has been swapped out for 'djutils.User' which has not been installed or is abstract.
I have this in my settings.py
AUTH_USER_MODEL = 'djutils.User'
(Notice the first case works)
Please advise!
Regards
Edit
djutils
models
__init__.py
from __future__ import absolute_import
from djutils.models.base import Manager, PrivateModel, Model
from djutils.models.user import UserManager, User
from djutils.models.passwordrecovery import PasswordRecoveryManager, PasswordRecovery
user.py
from djutils.models.base import Manager, Model
from djutils import mail
from djutils import settings
from django.contrib.auth.models import PermissionsMixin, AbstractBaseUser, BaseUserManager
from django.utils.translation import ugettext_lazy as _
from django.utils import timezone
from djutils import fields
class UserManager(Manager, BaseUserManager):
def create_user_instance(self, email, password, first_name, last_name, **extra_fields):
return user
def create_user(self, email, password, first_name, last_name, **extra_fields):
return user
def create_superuser(self, email, password, first_name, last_name, **extra_fields):
return user
class User(Model(20), AbstractBaseUser, PermissionsMixin):
# Basico info
first_name = fields.NameField(max_length=20, help_text=_('First name'))
last_name = fields.NameField(max_length=20, help_text=_('Last name'))
email = fields.EmailField(max_length=255, unique=True, help_text=_('Email'))
url = fields.URLField(help_text=_('Personal homepage'))
bio = fields.TextField(help_text=_('Biographic details'))
#picture = fields.ImageField(help_text=_('Profile picture'))
# Permissions
is_active = fields.BooleanField(default=False, help_text=_('Active user'))
is_staff = fields.BooleanField(default=False, help_text=_('Staff member'))
# Logging
date_joined = fields.DateTimeField(default=timezone.now)
# A string describing the name of the field on the User model that is used as the unique identifier
USERNAME_FIELD = 'email'
# A list of the field names that must be provided when creating a user via the createsuperuser management command
REQUIRED_FIELDS = ['first_name', 'last_name', 'password']
# Fields that are not returned by get_public
PRIVATE = ['is_active', 'is_superuser', 'is_staff', 'last_login', 'groups', 'user_permissions', 'password', 'id']
# Model manager
objects = UserManager()
class Meta:
swappable = 'AUTH_USER_MODEL'
permissions = ()
def send_mail(self, request, subject, body, context={}):
mail.send_mail(request, subject, body, [self.email], context)
def send_confirmation_email(self, request, context={}):
self.send_mail(request, settings.CONFIRMATION_SUBJECT, settings.CONFIRMATION_TEMPLATE, dict(context, **{
'redirect': request.build_absolute_uri(settings.CONFIRMATION_REDIRECT_URL)
}))
Set app_label = 'djutils' in your User model's Meta class.
See the app_label docs for more info.