我有這個類,我需要繼承。刪除超類變量
class AuthenticationForm(forms.Form):
username = forms.CharField(label=_("Username"), max_length=30)
password = forms.CharField(label=_("Password"), widget=forms.PasswordInput)
def __init__(self, request=None, *args, **kwargs):
super(AuthenticationForm, self).__init__(*args, **kwargs)
庫侖你告訴我,我怎麼能繼承這一點,並從超類中刪除username
變量?
class LoginForm(AuthenticationForm):
email = forms.EmailField(
required=True, label=_("Email")
)
def __init__(self, request, *args, **kwargs):
#del super(LoginForm, self).username
super(LoginForm, self).__init__(
request, *args, **kwargs
)
感謝
你意識到這(做天真,至少)會使得實例'ofAuthenticationForm '失去'用戶名'部分?也許它應該是相反的方向,否則你應該考慮共同的部分。即使這是可能的,它會相當混亂。 – delnan