Dori's Python Life in Words Journal

Use AbstractUser instead of import User


Subclassing AbstractUser for a custom User model in a Django project is considered good practice, as it provides flexibility and scalability for user management while maintaining compatibility with Django's built-in authentication system.

By subclassing AbstractUser, you can add custom fields and methods to your User model without losing any of Django's built-in authentication functionality. Even if you subclass AbstractUser and pass it as in my example, you'll still have the flexibility to customise your User model in the future. You won't have to perform complex migrations that can lead to errors.

Advice:
Use the AbstractUser subclass for your User model, even if you might not need it later, but you never know. Avoid future problems.

# account/models.py

from django.contrib.auth.models import AbstractUser


class User(AbstractUser):
    pass
# blog_project/settings.py

# set the User model:
AUTH_USER_MODEL = "account.User


Designed by BootstrapMade and modified by DoriDoro