diff --git a/bitfield/forms.py b/bitfield/forms.py index 6340548..961f818 100644 --- a/bitfield/forms.py +++ b/bitfield/forms.py @@ -28,12 +28,11 @@ def _has_changed(self, initial, data): class BitFormField(IntegerField): def __init__(self, choices=(), widget=BitFieldCheckboxSelectMultiple, *args, **kwargs): - - if isinstance(kwargs['initial'], int): - iv = kwargs['initial'] + initial = kwargs.get('initial') + if isinstance(initial, int): l = [] for i in range(0, 63): - if (1 << i) & iv > 0: + if (1 << i) & initial > 0: l += [choices[i][0]] kwargs['initial'] = l self.widget = widget