Django extending user model using a one-to-one link


Django ships with a built-in User model for authentication, however the official Django documentation highly recommends using a custom user model for new projects.

There are two modern ways to create a custom user model in Django: AbstractUser and AbstractBaseUser. In both cases we can subclass them to extend existing functionality however AbstractBaseUser requires much, much more work. So here we will use AbstractUser. We will also create a UserProfile model to store additional information of user with the help of One-To-One Link. After this we will extend the BaseUserManager functionality a little-bit. We will also configure signals to automatically create UserProfile whenever an User object is created. Finally we will customize django admin.

Read full article here:

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store