Home > front end >  Django Extend Default User Model
Django Extend Default User Model

Time:10-20

I am searching for a way to easily add more character fields to the default user model from Django. This question has been asked, but I couldn't find an up to date answer.

I let Django handle all the authenticating and logging in, so I don't want to create a custom user model, any ideas?

CodePudding user response:

from django.contrib.auth.models import AbstractUser
class CustomUser(AbstractUser):
      pass # add fields here

in settings.py add:

AUTH_USER_MODEL = "your_app_name.CustomUser"

CodePudding user response:

You can just inherit from AbstractUser.

class User(AbstractUser):
    custom_fields....

You can then set this as your AUTH_USER_MODEL in your settings.py:

AUTH_USER_MODEL = "<my-app>.User"

Django should still be able to handle all the authentication, etc.

  • Related