Created
May 5, 2014 06:29
-
-
Save litchfield/7f73238f55b7158b6852 to your computer and use it in GitHub Desktop.
Django Forms add_error() backport for <1.7
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
from django import forms | |
from django.forms.forms import NON_FIELD_ERRORS | |
class AddErrorMixin(object): | |
"Backport add_error() for django <1.7" | |
def add_error(self, field, msg): | |
field = field or NON_FIELD_ERRORS | |
if field in self._errors: | |
self._errors[field].append(msg) | |
else: | |
self._errors[field] = self.error_class([msg]) | |
class ExampleForm(AddErrorMixin, forms.Form): | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment