Ziqi Liu
Ziqi Liu

Reputation: 3171

Django best practice for extending User model

I want to extend the build-in User model in Django. I do this by just creating a subclass inherited from User. The main problem is that when I retrieve user = request.user, this user is the built-in User type instead of the new subclass I create. So I wonder what's the best practice to do this?

Upvotes: 0

Views: 1013

Answers (1)

user8060120
user8060120

Reputation:

i think you forget to add AUTH_USER_MODEL in the settings.py details in docs extending-the-existing-user-model, example:

AUTH_USER_MODEL = 'myapp.MyUser'

and by help in the comments, if you speak about best practice, better to use AbstractUser instead of User

from django.contrib.auth.models import AbstractUser

Upvotes: 5

Related Questions