Creating the User and Superuser
Explore how to create custom user and superuser models in Django by writing UserManager methods, setting up migrations, and testing the models within the Django shell. Understand the process of integrating these user models into the authentication system, which includes handling database changes and preparing data for client access.
We'll cover the following...
Let’s write UserManager so we can have methods to create a user and a superuser:
For the create_user method, we are basically making sure that fields such as password, email, username, first_name, and last_name are not None. If everything is good, we can confidently call the model, set a password, and save the user in the table.
This is done using the save() method.
The create_superuser method also behaves in accordance with the create_user method—this makes sense because, ...