1. 커스텀 User 모델 대체하기
❌ 명세에 적혀있는 User모델 필드를 따로 정의해야 한다고 생각했다.
⭕ 상속받는AbstractUser
에 클래스 속성으로 이미 포함되어 있음!
❌ User 모델 직접 참조함 : accounts/forms.py
에서 model = User
⭕ get_user_model()
: User 모델을 참조할 때(forms.py빼고 다)
# 1. django.contrib.auth.get_user_model()
# 2. from django.contrib.auth import get_user_model
⭕ AUTH_USER_MODEL
: 외래키로 User 모델을 참조할 때 대체 방법(forms.py에서만)
# from django.conf import settings
2. UserCreationForm 사용하기
❌ ArticleForm
을 만드는 것처럼 UserForm
을 정의하는 줄 알았다.
⭕ 회원가입할 때는 UserCreationForm
을 상속받아서 사용!!!
from django.contrib.auth import get_user_model
from django.contrib.auth.forms import UserCreationForm
class CustomUserCreationForm(UserCreationForm):
class Meta(UserCreationForm.Meta):
model = get_user_model()
fields = UserCreationForm.Meta.fields