from django.db import models
from django.contrib.auth.models import AbstractUser
from django.core.validators import RegexValidator
# Create your models here.
class User(AbstractUser):
class GenderChoices(models.TextChoices):
MALE = 'M', '남성'
FEMALE = 'F', '여성'
ETC = 'E', '기타'
gender = models.CharField(
max_length=1,
blank=True,
choices=GenderChoices,
default=GenderChoices.ETC
)
bio = models.TextField()
phone_number = models.CharField(
max_length=13,
blank=True,
validators=[RegexValidator(r'010-?\d{4}-?\d{4}')],
)
profile_photo = models.ImageField(upload_to='accounts/profile_photo/%Y/%m/%d')
models.py 성별 전화번호 모델 makemigrations을 할려는데...
$ python manage.py makemigrations SystemCheckError: System check identified some issues:
ERRORS: accounts.User.gender: (fields.E005) 'choices' must be an iterable containing (actual value, human readable name) tuples.
오류가 났다..
해결방법
from django.db import models
from django.contrib.auth.models import AbstractUser
from django.core.validators import RegexValidator
# Create your models here.
class User(AbstractUser):
class GenderChoices(models.TextChoices):
MALE = 'M', '남성'
FEMALE = 'F', '여성'
ETC = 'E', '기타'
gender = models.CharField(
max_length=1,
blank=True,
choices=GenderChoices.choices,
default=GenderChoices.ETC
)
bio = models.TextField()
phone_number = models.CharField(
max_length=13,
blank=True,
validators=[RegexValidator(r'010-?\d{4}-?\d{4}')],
)
profile_photo = models.ImageField(upload_to='accounts/profile_photo/%Y/%m/%d')
choices=GenderChoices에 .choices를 넣어야 했다 그러니 해결이 되었다!