dangerChihuahua007
dangerChihuahua007

Reputation: 20915

Why isn't my overriden clean_password function not working?

I a form that subclasses another form in Django:

class RegistrationForm(forms.Form):
    ...
    def clean_password(self):
            if not re.search('[a-zA-Z]', self.data['password']):
                raise forms.ValidationError('Must contain a letter.')
            return self.data['password']

class addNewFamilyMemberForm(RegistrationForm):
    ...
    def clean_password(self):
        if self.data["username"]:
            super.clean_password(self)
        return self.data["password"]

Why is Django producing this error?

type object 'super' has no attribute 'clean_password'

The superclass of addNewMemberForm clearly has a clean_password function.

Upvotes: 0

Views: 325

Answers (2)

Ned Batchelder
Ned Batchelder

Reputation: 375854

In Python 2, you need to use super like this:

super(addNewFamilyMemberForm, self).clean_password()

You should probably be using the return value somehow, but I'm not sure how.

Also, class names should start with a capital letter, though that doesn't affect how it works.

Upvotes: 5

JoseP
JoseP

Reputation: 641

super is not actually an object, and you can not do "super.method". Maybe you should change that line to something like

super(addNewFamilyMemberForm, self).clean_password()

Upvotes: 1

Related Questions