Django Extending or Substituting User Model Referencing the User model


Your code will not work in projects where you reference the User model (and where the AUTH_USER_MODEL setting has been changed) directly.

For example: if you want to create Post model for a blog with a customized User model, you should specify the custom User model like this:

from django.conf import settings
from django.db import models

class Post(models.Model):
    author = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)