Skip to content
This repository

correct selection logic for QuerySetSelectMultipleField #38

Closed
wants to merge 1 commit into from

1 participant

Paul Swartz
Paul Swartz

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.

Paul Swartz paulswartz correct selection logic for QuerySetSelectMultipleField
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.
d2ba88d
Paul Swartz

Closing in favor of #27.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Apr 04, 2013
Paul Swartz paulswartz correct selection logic for QuerySetSelectMultipleField
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.
d2ba88d
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 12 additions and 0 deletions. Show diff stats Hide diff stats

  1. +12 0 flask_mongoengine/wtf/fields.py
12 flask_mongoengine/wtf/fields.py
@@ -85,6 +85,18 @@ def __init__(self, label=u'', validators=None, queryset=None, label_attr='',
85 85 allow_blank=False, blank_text=u'---', **kwargs):
86 86 super(QuerySetSelectMultipleField, self).__init__(label, validators, queryset, label_attr, allow_blank, blank_text, **kwargs)
87 87
  88 + def iter_choices(self):
  89 + if self.allow_blank:
  90 + yield (u'__None', self.blank_text, self.data is None)
  91 +
  92 + if self.queryset == None:
  93 + return
  94 +
  95 + self.queryset.rewind()
  96 + for obj in self.queryset:
  97 + label = self.label_attr and getattr(obj, self.label_attr) or obj
  98 + yield (obj.id, label, obj in self.data)
  99 +
88 100 def process_formdata(self, valuelist):
89 101 if valuelist:
90 102 if valuelist[0] == '__None':

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.