Skip to content

Commit

Permalink
correct selection logic for QuerySetSelectMultipleField
Browse files Browse the repository at this point in the history
Previously, it was using the default behavior from QuerySetSelectField.
However, this compared the current object to the list of selected values,
which meant none of the them were marked as selected in the admin.
  • Loading branch information
paulswartz committed Apr 4, 2013
1 parent 21e0152 commit d2ba88d
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions flask_mongoengine/wtf/fields.py
Expand Up @@ -85,6 +85,18 @@ def __init__(self, label=u'', validators=None, queryset=None, label_attr='',
allow_blank=False, blank_text=u'---', **kwargs):
super(QuerySetSelectMultipleField, self).__init__(label, validators, queryset, label_attr, allow_blank, blank_text, **kwargs)

def iter_choices(self):
if self.allow_blank:
yield (u'__None', self.blank_text, self.data is None)

if self.queryset == None:
return

self.queryset.rewind()
for obj in self.queryset:
label = self.label_attr and getattr(obj, self.label_attr) or obj
yield (obj.id, label, obj in self.data)

def process_formdata(self, valuelist):
if valuelist:
if valuelist[0] == '__None':
Expand Down

0 comments on commit d2ba88d

Please sign in to comment.