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

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -