我正在使用django-userena authuentication。我试图将models.py中的性别定义模型引用到forms.py中以显示在用户注册中,但它在关键字arg(forms.py,第23行)之后的非关键字arg中显示SyntaxError。我不知道如何正确引用它。请帮忙!!!
models.py:
class Profile(UserenaLanguageBaseProfile):
GENDER_CHOICES = (
(1, _('Male')),
(2, _('Female')),
)
gender = models.PositiveSmallIntegerField(_('gender'),
choices=GENDER_CHOICES,
blank=False,
null=False)
forms.py:
from django import forms
from userena.models import UserenaLanguageBaseProfile
from accounts.models import Profile
from userena.forms import SignupForm
class SignupFormExtra(SignupForm):
gender = forms.PositiveSmallIntegerField(label=_(u'Gender'),
'gender',
required=True)
first_name = forms.CharField(label=_(u'First name'),
max_length=30,
required=True)
last_name = forms.CharField(label=_(u'Last name'),
max_length=30,
required=True)
答案 0 :(得分:0)
尝试forms.ChoiceField https://docs.djangoproject.com/en/dev/ref/forms/fields/#django.forms.ChoiceField
class SignupFormExtra(SignupForm):
gender = forms.ChoiceField(label=_(u'Gender'), choices=GENDER_CHOICES, default=1
required=True)