common은 애플리케이션 폴더입니다.
유저 모델
# common/models.py
from django.db import models
from django.contrib.auth.models import AbstractUser
# Create your models here.
class User(AbstractUser):
pass
유저 모델 어드민 페이지에 등록
# common/admin.py
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from .models import User
# Register your models here.
admin.site.register(User, UserAdmin)
config는 프로젝트 폴더입니다.
# config/settings.py
AUTH_USER_MODEL = 'common.User'
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'corsheaders',
'rest_framework',
'rest_framework.authtoken',
'rest_framework_simplejwt',
'dj_rest_auth',
'dj_rest_auth.registration',
'allauth',
'allauth.account',
'allauth.socialaccount',
'api',
'common',
]
SITE_ID = 1
ACCOUNT_EMAIL_VERIFICATION = 'none'
REST_FRAMEWORK = {
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
'PAGE_SIZE': 10,
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework_simplejwt.authentication.JWTAuthentication',
)
}
# config/urls.py
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('api-auth/', include('rest_framework.urls')),
path('common/', include('common.urls')),
]
dj-rest-auth 관련 기능 urls.py
# common/urls.py
from django.urls import path, include
urlpatterns = [
path('', include('dj_rest_auth.urls')),
path('registration/', include('dj_rest_auth.registration.urls')),
]
python manage.py makemigrations common
python manage.py migrate