Quickstart: Using Improved User
This document provides a quick tutorial for the recommended way to setup Improved User.
See Select a Configuration Method for Improved User for an overview of options and tradeoffs.
Installation
In a Terminal, use pip to install the package from PyPI.
To use the UserFactory provided
by the package to allow for testing with factory-boy, include it
in the installation.
$ pip install django-improved-user[factory]
If factory-boy is unnecessary, it can be omitted by installing normally.
$ pip install django-improved-user
Configuration and Usage
In a Django project, create a new app. For the purposes of this documentation, we will assume the name of your new app is
user_app, but you could name it whatever you wish.$ python3 manage.py startapp user_app
In your project’s settings, add
user_app.apps.UserAppConfigtoINSTALLED_APPS(replaceuser_appandUserAppConfigas necessary).In
user_app/models.py, import Improved User’sAbstractUser.Create a new
Usermodel. If you omit comments, you may need to addpassto the line below the class.# pylint: disable=too-many-ancestors class User(AbstractUser):
Attention
If you add your own fields to the model, you may wish to modify
REQUIRED_FIELDS.
Define or replace
AUTH_USER_MODELin your project settings with the new model, as below (replaceuser_appwith the name of your own app).AUTH_USER_MODEL='user_app.User'
Tip
Remember to use get_user_model() to
get your new model. Don’t import it directly!
While still in settings, change
UserAttributeSimilarityValidatorto match correctAbstractUserfields, as shown below.AUTH_PREFIX = 'django.contrib.auth.password_validation.' AUTH_PASSWORD_VALIDATORS = [ { 'NAME': AUTH_PREFIX + 'UserAttributeSimilarityValidator', 'OPTIONS': { 'user_attributes': ('email', 'full_name', 'short_name') }, }, # include other password validators here ]
You’re done! 🎉 Run migrations or go back to programming the rest of your project.
Note
Improved user also comes with forms, test factories, and an admin panel. Take a look at the Package Reference for more information.