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:
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user