我在User
中创建了继承AbstractUser
的自定义Django
模型:
class ChachaUser(AbstractUser):
birth = models.DateField()
gender = models.CharField(max_length=1, choices=GENDER_CHOICES)
和我的CustomUserCreationForm
:
GENDER_CHOICES = (
('M', '남'),
('F', '여'),
)
class MyUserCreationForm(UserCreationForm):
birth = forms.DateField(
widget=forms.SelectDateWidget(
years=range(1970, 2015)
),
required=True,
)
gender = forms.ChoiceField(choices=GENDER_CHOICES, initial='M')
class Meta(UserCreationForm.Meta):
model = ChachaUser
fields = UserCreationForm.Meta.fields + ('birth', 'gender')
但我希望python manage.py createsuperuser
创建超级用户,我也必须实现CustomUserManager
。
答案 0 :(得分:2)
您对UserManager
(code)感兴趣。
示例:
from django.contrib.auth.models import AbstractUser, UserManager
class CustomUserManager(UserManager):
# your methods
class CustomUser(AbstractUser):
# fields
objects = CustomUserManager()
答案 1 :(得分:0)
或者这样:
class CustomUser(User):
objects = MyManager()
class Meta(object):
proxy=True