ruk·si

🍡 Django Tutorial
Custom User Class

Updated at 2018-11-23 18:12

Create djangor/models/users.py: This is required to customize user entities in the future.

from django.contrib.auth.models import AbstractUser

from djangor.model_mixins import UUIDMixin


class User(UUIDMixin, AbstractUser):
    pass

Create djangor/models/__init__.py:

from .users import User

Create djangor/admin.py:

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

admin.site.register(User, UserAdmin)

Add following to djangor/settings.py:

# Application definition
INSTALLED_APPS = [
    # ...
    'djangor',
]

# User substitution
# https://docs.djangoproject.com/en/1.11/topics/auth/customizing/#auth-custom-user
AUTH_USER_MODEL = 'djangor.User'

Start the application

python manage.py makemigrations djangor
python manage.py migrate
python manage.py runserver
# navigate to http://localhost:8000/ to see your new django project in action
# dev server automatically reloads Python code for each request as needed