Skip to content

Commit

Permalink
Merge pull request #35 from habfast/patch-1
Browse files Browse the repository at this point in the history
fix BitFieldCheckboxSelectMultiple for new form
  • Loading branch information
dcramer committed May 11, 2015
2 parents 08f20ab + 2805804 commit 24126a0
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions bitfield/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down

0 comments on commit 24126a0

Please sign in to comment.