diff options
Diffstat (limited to 'django/forms')
| -rw-r--r-- | django/forms/widgets.py | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/django/forms/widgets.py b/django/forms/widgets.py index 1fbef98deb..4813af69e9 100644 --- a/django/forms/widgets.py +++ b/django/forms/widgets.py @@ -487,15 +487,18 @@ class TimeInput(Input): pass return super(TimeInput, self)._has_changed(self._format_value(initial), data) + +# Defined at module level so that CheckboxInput is picklable (#17976) +def boolean_check(v): + return not (v is False or v is None or v == '') + + class CheckboxInput(Widget): def __init__(self, attrs=None, check_test=None): super(CheckboxInput, self).__init__(attrs) # check_test is a callable that takes a value and returns True # if the checkbox should be checked for that value. - if check_test is None: - self.check_test = lambda v: not (v is False or v is None or v == '') - else: - self.check_test = check_test + self.check_test = boolean_check if check_test is None else check_test def render(self, name, value, attrs=None): final_attrs = self.build_attrs(attrs, type='checkbox', name=name) |
