Django Extend User Model
How to extend the default user model in Django with more fields
This page explains how to extend the default User Model in Django and associate with a user other information like address, phone number .. etc.
​
t what if you need more fields? Such as address, phone number, city ...etc. In that case, you can just extend the user model, here the AbstractUser class.
1
from django.db import models
2
from django.contrib.auth.models import AbstractUser
3
​
4
class CustomUser(AbstractUser):
5
"""
6
The User model has already:
7
- first name
8
- last name
9
- email
10
- username
11
- is_active
12
- is_staff
13
- date_joined
14
- last_login
15
"""
16
​
17
phone = models.CharField(max_length=35, blank=True, null=True)
18
address = models.CharField(max_length=255, blank=True, null=True)
19
address_number = models.CharField(max_length=35, blank=True, null=True)
20
city = models.CharField(max_length=35, blank=True, null=True)
21
​
Copied!
Once it's done, you'll need to add a manager. The manager will tell Django how to create a new user or a super user.
​
Last modified 8d ago
Copy link