diff --git a/bitfield/forms.py b/bitfield/forms.py index 6340548..ec15fd0 100644 --- a/bitfield/forms.py +++ b/bitfield/forms.py @@ -11,6 +11,15 @@ class BitFieldCheckboxSelectMultiple(CheckboxSelectMultiple): def render(self, name, value, attrs=None, choices=()): if isinstance(value, BitHandler): value = [k for k, v in value if v] + elif isinstance(value, int): + real_value = [] + div = 2 + for (k, v) in self.choices: + if value % div != 0: + real_value.append(k) + value -= (value % div) + div *= 2 + value = real_value return super(BitFieldCheckboxSelectMultiple, self).render( name, value, attrs=attrs, choices=enumerate(choices))