1
0
mirror of https://github.com/django/django.git synced 2025-10-30 00:56:09 +00:00

Fixed #23167 -- Added BaseForm.__repr__()

Thanks Keryn Knight for the idea.
This commit is contained in:
areski
2014-08-21 19:09:05 +02:00
committed by Tim Graham
parent 0396cd8f19
commit a6691e5dcf
2 changed files with 36 additions and 0 deletions

View File

@@ -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]