** Note that we did not run migrate to configure our database. It’s important to wait until after we’ve created our new custom user model before doing so.
from django.contrib.auth.models import AbstractUser from django.db import models
class CustomUser(AbstractUser): pass # add additional fields in here
def __str__(self):
return self.username ``` 3. create new UserCreation and UserChangeForm * create a new file in the accounts app called forms.py. ``` accounts/forms.py from django import forms from django.contrib.auth.forms import UserCreationForm, UserChangeForm from .models import CustomUser
class CustomUserCreationForm(UserCreationForm):
class Meta:
model = CustomUser
fields = ('username', 'email')
class CustomUserChangeForm(UserChangeForm):
class Meta:
model = CustomUser
fields = ('username', 'email') ```
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’, ‘username’,]
admin.site.register(CustomUser, CustomUserAdmin)
5. run makemigrations and migrate for the first time to create a new database that uses the custom user model.
#### Superuser
* createsuperuser
* To set the redirect links for log in and log out, which will both go to our home template. Add these two lines at the bottom of the file.
LOGIN_REDIRECT_URL = ‘home’ LOGOUT_REDIRECT_URL = ‘home’ ```