# settings.py
DJANGO_APPS = [
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
]
PROJECT_APPS= [
"users.apps.UsersConfig",
]
INSTALLED_APPS = DJANGO_APPS + PROJECT_APPS
AUTH_USER_MODEL = "users.User"
# users.models.py
from django.db import models
from django.contrib.auth.models import AbstractUser
# AbstractUser 요놈이 임포트 돼서 파라미터로 넘겨 주어야만 기존 user model을 유지하며 다른것을 추가할수있다.
class User(AbstractUser):
"""Custom User Model"""
"""Custom User Model Fields"""
gender = models.CharField(choices=GENDER_CHOICES, max_length=10, blank=True)
birthday = models.DateField(blank=True, null=True)
language = models.CharField(choices=LANGUAGE_CHOICES, max_length=2, blank=True)
def __str__(self) -> str:
return self.username
# users.admin.py
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from . import models
# Decorator를 이용해 등록한다.
@admin.register(models.User)
class CustomUserAdmin(UserAdmin):
"""Custom User Model"""
# admin user detail page에서 보여줄 fields 설정
fieldsets = UserAdmin.fieldsets + (
(
"Custom Profile",
{
"fields": (
"gender",
"birthday",
"language",
)
},
),
)