+# -*- coding: utf-8 -*-
from django import forms
from django.forms.models import ModelChoiceIterator
from django.utils.translation import ugettext as _
def choice(self, obj):
items_query = self.items_queryset.filter(**{self.field.grouping_fk_field: obj})
items = [super(GroupedModelChoiceIterator, self).choice(item) for item in items_query.all()]
- return (unicode(obj), items)
+ return unicode(obj), items
class GroupedModelChoiceField(forms.ModelChoiceField):
class PostForm(pybb.forms.PostForm):
- lesson = GroupedModelChoiceField(label = _('Related lesson'), queryset = Lesson.objects.all(),
- grouping_fk_field = 'section', required = False)
+ lesson = GroupedModelChoiceField(
+ label=_('Related lesson'), queryset=Lesson.objects.all(),
+ grouping_fk_field='section', required=False)