From 844ae40a7cdcb1738ca3a2e8f13bb6b8c2e22efd Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Sat, 15 Apr 2017 13:01:38 -0400 Subject: [1.11.x] Fixed #28058 -- Restored empty BoundFields evaluating to True. Regression in b52c73008a9d67e9ddbb841872dc15cdd3d6ee01 Backport of c09bf8d76770d39a4d9545b67598cd05adee281b from master --- django/forms/boundfield.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'django') diff --git a/django/forms/boundfield.py b/django/forms/boundfield.py index a1063b2b05..a8e81afe9b 100644 --- a/django/forms/boundfield.py +++ b/django/forms/boundfield.py @@ -57,6 +57,13 @@ class BoundField(object): for widget in self.field.widget.subwidgets(self.html_name, self.value(), attrs=attrs) ) + def __bool__(self): + # BoundField evaluates to True even if it doesn't have subwidgets. + return True + + def __nonzero__(self): # Python 2 compatibility + return type(self).__bool__(self) + def __iter__(self): return iter(self.subwidgets) -- cgit v1.3