Django User/ Custom Usermodel

Viewed 27

What is the difference between creating a custom User with AbstractBaseUser and building an userProfile ontop of the user model by referencing it with onetoone=?

1 Answers

The first case, you are replacing fully the user model of Django.contrib.auth by your own model as you told. So you have only one table created in db. You do not have join when you want to query on user etc...

But for this case works correctly you have to make this change when you create your project. Very dificult you move on a custom user model after developing some apps (it is possible, but very complicated with many custom migrations to do etc...)

The second case allow you to not change the default behaviour of Django, but your have two tables in your db and you have to make join each time you need to access to UserProfile from auth.User or access to auth.User from UserProfile.

Today, i think it is better for new projet to start with a custom User model. It is very easely, and more simple than your second case when you are coding to get user informations without think about architecture between profile and user models

Related