css - Override ModelForm is_valid function -


i want provide forms nicer feedback using css. i'm doing it's clean code matter. have many modelforms , want of them behave in same way, thought there should way avoid duplicating code validation.

i have created new class overrides modelform

class modelformcss(forms.modelform):     def is_valid(self):         # run parent validation first         valid = super(-->parentmodelform<--, self).is_valid()          if not valid:             f_name in self.errors:                 classes = self.fields[f_name].widget.attrs.get('class', '')                 if not "errors" in classes:                     classes += ' errors'                     self.fields[f_name].widget.attrs['class'] = classes             return valid          #         return true 

my problem lies in runing parent validation since don't know how parent form... isn't there way self?

you've misunderstood how inheritance works in python. in super method, must call current class:

valid = super(modelformcss, self).is_valid() 

Comments

Popular posts from this blog

c# - SelectList with Dictionary, add values to the Dictionary after it's assigned to SelectList -

how can i manage url using .htaccess in php? -

ios - I get the error Property '...' not found on object of type '...' -