Customizing the User model
There are primarily two approaches via which we can customize the User
model. Both of them have their equal advantages, so let us learn about them one by one:
- Extending the User model by a one-to-one relation: Whenever there is a requirement to add additional fields to the user, this is one of the simplest and best solutions. In this approach, we would create a new model, say
UserProfile
, and then create a one-to-one relationship with theUser
model. Any new custom field would be added to theUserProfile
model. I would recommend using this approach most of the time since this is one of the simplest and cleanest solutions that doesn’t need much effort from the developer’s end and serves our requirements. - Expand using AbstractUser and AbstractBaseUser model: This is another approach to expand the
User
model. In this approach, we would have to create our customUser
model and inherit from theAbstractUser
class orAbstractBaseUser
class...