Skip to content

Instantly share code, notes, and snippets.

@litchfield
Created May 5, 2014 06:29
Show Gist options
  • Save litchfield/7f73238f55b7158b6852 to your computer and use it in GitHub Desktop.
Save litchfield/7f73238f55b7158b6852 to your computer and use it in GitHub Desktop.
Django Forms add_error() backport for <1.7
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