summaryrefslogtreecommitdiff
path: root/django/forms
diff options
context:
space:
mode:
authorareski <areski@gmail.com>2014-08-21 19:09:05 +0200
committerTim Graham <timograham@gmail.com>2014-08-22 15:55:56 -0400
commita6691e5dcfdfd1529987be3bdcf06e7ab9948356 (patch)
tree2b3a53f3713abba874010a4e11c636843bfcf3af /django/forms
parent0396cd8f190b39597516abf2162542b196cf0c6d (diff)
Fixed #23167 -- Added BaseForm.__repr__()
Thanks Keryn Knight for the idea.
Diffstat (limited to 'django/forms')
-rw-r--r--django/forms/forms.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/django/forms/forms.py b/django/forms/forms.py
index e5df320673..d631b8f928 100644
--- a/django/forms/forms.py
+++ b/django/forms/forms.py
@@ -134,6 +134,18 @@ class BaseForm(object):
def __str__(self):
return self.as_table()
+ def __repr__(self):
+ if self._errors is None:
+ is_valid = "Unknown"
+ else:
+ is_valid = self.is_bound and not bool(self._errors)
+ return '<%(cls)s bound=%(bound)s, valid=%(valid)s, fields=(%(fields)s)>' % {
+ 'cls': self.__class__.__name__,
+ 'bound': self.is_bound,
+ 'valid': is_valid,
+ 'fields': ';'.join(self.fields),
+ }
+
def __iter__(self):
for name in self.fields:
yield self[name]