开发者

Deleting a super classes variable

I have this class which I need to inherit.

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)

Coul you tell me how I could inherit this and remove the username variable from the super class?

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
        )

Thanks


Since this is Django, you can just remove it from the fields dict:

class LoginForm(…):
    def __init__(…):
        super(LoginForm, self).__init__(…)
        self.fields.pop('username')
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜