In our project we will manage the user data in the following ways:
Custom user model: In this model we will store ALL user data unrelated to authentication. It will be related to the User model using a OneToOneField. We will try to avoid updating the User model completely and if there are any fields required from that model we will simply add them to the new custom model.
AllAuth: AllAuth is a popular third-party module that handles user authentication and password/email management. It provides simple URL mappings such as account_signup, account_login, account_logout, account_reset_password, and account_email that handle all necessary forms, views, and templates for these functions.
User model: The User model is a default Django model that represents all users in the system. It comes with a set number of fields, including username, password, email, first_name, last_name, is_staff, is_active, date_joined, and last_login. However, no extra fields can be added or removed from this model.
When it comes to creating forms, views, and templates for user data, we will focus on the custom user model and disregard the default User model. By adding first_name, last_name, and any other desired fields to the custom model, you can provide a more streamlined and user-friendly experience. Meanwhile, AllAuth can handle all password and email management, with a simple link to reset the email as needed.
Create / Update CUSTOM USER MODEL
models.py
forms.py
views.py
Templates crete a new user_profile_create_update.html file:
urls.py
Allauth url mappings
{% url 'account_signup' %}
{% url 'account_login' %}
{% url 'account_logout' %}
{% url 'account_reset_password' %}
{% url 'account_email' %}
Display email used with the AllAuth authentication: As the email can be different to the user email stored in the User model, you can use this code instead:
Display User Profile
views.py
urls.py
Template: create a new user_profile.html file:
USER MODEL
The approach in this project is to include the relevant User Model fields in the Custom Profile Model, but in case it is required here is how to edit the User Model.
It is possible to use Django signals and create/update a custom user model every time the user model is updated, but for our project purposes the better solution will be to simply create a new custom model and disregard the user model completely.
forms.py Create a custom form to remove all the fields which are irrelevant to users:
self.fields.pop('password', None) removes the password prompt from the form
views.py
Tempaltes: create a new user_account_update.html file: