reading-notes

Readings: Django Custom User Summary :

class CustomUser(AbstractUser): pass # add additional fields in here

def __str__(self):
    return self.username ``` 3. create new UserCreation and UserChangeForm   * create a new file in the accounts app called forms.py. ```  accounts/forms.py from django import forms from django.contrib.auth.forms import UserCreationForm, UserChangeForm from .models import CustomUser

class CustomUserCreationForm(UserCreationForm):

class Meta:
    model = CustomUser
    fields = ('username', 'email')

class CustomUserChangeForm(UserChangeForm):

class Meta:
    model = CustomUser
    fields = ('username', 'email') ```
  1. update the admin ```

    accounts/admin.py

    from django.contrib import admin from django.contrib.auth.admin import UserAdmin

from .forms import CustomUserCreationForm, CustomUserChangeForm from .models import CustomUser

class CustomUserAdmin(UserAdmin): add_form = CustomUserCreationForm form = CustomUserChangeForm model = CustomUser list_display = [‘email’, ‘username’,]

admin.site.register(CustomUser, CustomUserAdmin)

5. run makemigrations and migrate for the first time to create a new database that uses the custom user model.

#### Superuser
* createsuperuser
* To set the redirect links for log in and log out, which will both go to our home template. Add these two lines at the bottom of the file.

config/settings.py

LOGIN_REDIRECT_URL = ‘home’ LOGOUT_REDIRECT_URL = ‘home’ ```