我有一个继承自其他2种形式的形式。在我的表单中,我想更改在父表单之一中定义的字段的标签。有谁知道该怎么做?
我正在尝试在自己的服务器中执行此操作__init__
,但是它抛出一个错误,指出“'RegistrationFormTOS'对象没有属性'email'”。有人知道我该怎么做吗?
谢谢。
这是我的表单代码:
from django import forms
from django.utils.translation import ugettext_lazy as _
from registration.forms import RegistrationFormUniqueEmail
from registration.forms import RegistrationFormTermsOfService
attrs_dict = { 'class': 'required' }
class RegistrationFormTOS(RegistrationFormUniqueEmail, RegistrationFormTermsOfService):
"""
Subclass of ``RegistrationForm`` which adds a required checkbox
for agreeing to a site's Terms of Service.
"""
email2 = forms.EmailField(widget=forms.TextInput(attrs=dict(attrs_dict, maxlength=75)), label=_(u'verify email address'))
def __init__(self, *args, **kwargs):
self.email.label = "New Email Label"
super(RegistrationFormTOS, self).__init__(*args, **kwargs)
def clean_email2(self):
"""
Verifiy that the values entered into the two email fields
match.
"""
if 'email' in self.cleaned_data and 'email2' in self.cleaned_data:
if self.cleaned_data['email'] != self.cleaned_data['email2']:
raise forms.ValidationError(_(u'You must type the same email each time'))
return self.cleaned_data