Custom User Model (AbstractUser)
Django strongly recommends creating a custom user model at the START of every project. AbstractUser lets you extend the default User with additional fields. Changing user models after the project has data is very difficult.
20 min•By Priygop Team•Updated 2026
Why Custom User Model?
- Add fields: phone, avatar, bio, role without a separate Profile
- Use email as username instead of a username field
- Start every project with a custom user model (Django best practice)
- AbstractUser — Extends default User (easiest approach)
- AbstractBaseUser — Build from scratch (advanced)
- AUTH_USER_MODEL = 'accounts.CustomUser' in settings.py
- Must be done BEFORE first migration
Custom User Model
Custom User Model
# accounts/models.py
# from django.contrib.auth.models import AbstractUser
# from django.db import models
# class CustomUser(AbstractUser):
# # Additional fields
# email = models.EmailField(unique=True)
# phone = models.CharField(max_length=20, blank=True)
# bio = models.TextField(blank=True)
# avatar = models.ImageField(upload_to='avatars/', blank=True)
# date_of_birth = models.DateField(null=True, blank=True)
#
# ROLE_CHOICES = [
# ('student', 'Student'),
# ('instructor', 'Instructor'),
# ('admin', 'Admin'),
# ]
# role = models.CharField(max_length=20, choices=ROLE_CHOICES, default='student')
#
# def __str__(self):
# return self.username
#
# @property
# def is_instructor(self):
# return self.role == 'instructor'
# settings.py
# AUTH_USER_MODEL = 'accounts.CustomUser'
# accounts/admin.py
# from django.contrib import admin
# from django.contrib.auth.admin import UserAdmin
# from .models import CustomUser
#
# class CustomUserAdmin(UserAdmin):
# model = CustomUser
# list_display = ['username', 'email', 'role', 'is_staff']
# fieldsets = UserAdmin.fieldsets + (
# ('Extra Fields', {'fields': ('phone', 'bio', 'avatar', 'role')}),
# )
# admin.site.register(CustomUser, CustomUserAdmin)
# In other models — reference with settings.AUTH_USER_MODEL
# from django.conf import settings
# class Post(models.Model):
# author = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)Tip
Tip
Create a custom User model BEFORE your first migration. Use AbstractUser for simple extensions, AbstractBaseUser for full control.
Diagram
Loading diagram…
QuerySets are LAZY — no DB hit until evaluated.
Common Mistake
Warning
Adding fields to the default User model after migrations. Custom user models MUST be created before the first migrate.
Practice Task
Note
(1) Create a custom User model with AbstractUser. (2) Add profile fields. (3) Update AUTH_USER_MODEL in settings.
Quick Quiz
Key Takeaways
- Django strongly recommends creating a custom user model at the START of every project.
- Add fields: phone, avatar, bio, role without a separate Profile
- Use email as username instead of a username field
- Start every project with a custom user model (Django best practice)