Django Custom User


Django Custom User

Always use a custom user model for all new Django projects

  • The official Django documentation highly recommends using a custom user model for new projects, The reason is if you want to make any changes to the User model down the road, using a custom user model from the beginning makes this quite easy.

AbstractUser vs AbstractBaseUser

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.

Superuser

It’s helpful to create a superuser that we can use to login to the admin and test out login/logout.

(users) $ python manage.py createsuperuser

Conclusions

  • Django ships with a built-in User model for authentication
  • It’s helpful to create a superuser that we can use to login to the admin and test out login/logout
  • USERNAME_FIELD = ‘email’ will define that the email is what will be used to login
  • REQUIRED_FILEDS = ['username'] requires the user to setup a username when creating an account
  • requirded functions has_perm and has_module_perms to setup a custom user