How to remove a field from the parent Form in a subclass?

前端 未结 4 1981
太阳男子
太阳男子 2020-12-06 03:57
class LoginForm(forms.Form):
    nickname = forms.CharField(max_length=100)
    username = forms.CharField(max_length=100)
    password = forms.CharField(widget=form         


        
4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-06 04:41

    You can alter the fields in a subclass by overriding the init method:

    class LoginFormWithoutNickname(LoginForm):
        def __init__(self, *args, **kwargs):
            super(LoginFormWithoutNickname, self).__init__(*args, **kwargs)
            self.fields.pop('nickname')
    

提交回复
热议问题