我正在编写一个自定义用户模型字段。
当我这样做时,我意识到我在“models.py”和“forms.py”之间复制代码??
例如:
模型.py
class MyUser(AbstractBaseUser):
email = models.EmailField(
verbose_name='email address',
max_length=255,
unique=True,
db_index=True,
)
full_name = forms.CharField(
max_length=64,
)
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = ['full_name']
...
表格.py
class RegistrationForm(forms.Form):
error_css_class = 'error'
required_css_class = 'required'
email = forms.EmailField(
label=_("Email"),
)
full_name = forms.CharField(
label=_("Full Name"),
)
password1 = forms.CharField(
widget=forms.PasswordInput,
label=_("Password"),
)
password2 = forms.CharField(
widget=forms.PasswordInput,
label=_("Password (again)"),
)
...
在这里,我发现自己定义了两次字段,但我不知道这是否有必要,如果没有,那么我如何将这两个字段组合在一行中:(
任何想法?
谢谢。