我试图创建一个定制的注册表单,但是我不知道如何去做,因为我试图将默认的django注册与一个新的模型连接起来。在
这是它看起来的样子,可能是错的,但我正在考虑这样的事情。在
模型.pyclass Profile(models.Model):
user = models.OneToOneField(User)
name = models.CharField(max_length=20, blank=True, null=True)
description = models.TextField(max_length=400)
视图.py
^{pr2}$
表单.pyclass MyRegistrationForm(UserCreationForm):
email = forms.EmailField(required=True)
class Meta:
model = User
fields = {'username', 'password1', 'password2', 'email'}
def save(self, commit=True):
my_user = super(MyRegistrationForm, self).save(commit=False)
my_user.email = self.cleaned_data['email']
new_profile = Profile(user=my_user, name="John", description="a person")
if commit:
new_profile.save()
return new_profile
寄存器.py
{% csrf_token %}
{{ form.username.errors }}
{{ form.username.label_tag }}
{{ form.username }}
[... other fiels ...]
我试图将模型与表单连接起来,所以当有人注册时,当我在模板中输入他的名字时,应该是“John”。在
我怎样才能达到这个目标?在