Last active
December 18, 2015 03:39
-
-
Save venkatesh22/5719704 to your computer and use it in GitHub Desktop.
Space Validation In Django
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class _BaseForm(object): | |
def clean(self): | |
for field in self.cleaned_data: | |
if isinstance(self.cleaned_data[field], basestring): | |
self.cleaned_data[field] = self.cleaned_data[field].strip() | |
return self.cleaned_data | |
class BaseModelForm(_BaseForm, forms.ModelForm): | |
pass | |
################# IF YOU HAVE UNIQUE TO GETHER/ANY OTHER VALIDATIONS CALL SUPER CLEAN METHOD###################### | |
class _BaseForm(forms.ModelForm): | |
def clean(self): | |
for field in self.cleaned_data: | |
if isinstance(self.cleaned_data[field], basestring): | |
self.cleaned_data[field] = self.cleaned_data[field].strip() | |
return super(_BaseForm, self).clean() | |
class BaseModelForm(_BaseForm): | |
pass | |
class ContactMarketingForm(BaseModelForm): | |
class Meta: | |
model = ContactMarketing | |
exclude = ('contact',) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment