django-forms-builder
django-forms-builder copied to clipboard
custom ModelMultipleChoiceField, initial values
I've developed a new custom field, a custom multiple select. I guess it should be added to this tuple:
MULTIPLE = (CHECKBOX_MULTIPLE, SELECT_MULTIPLE)
otherwise, initial values don't seem to be calculated correctly (I have {{request.GET.offer}}, when passing offer=60, it populates with 60 and 6...).
what would be the proper way to add my field to the MULTIPLE tuple?
couldn't there be a check if the field inherits from a multiple base field, so the MULTIPLE
would be obsolete?
Can you provide the code needed to reproduce your example?
the field (widget is not really interesting/important).
class OfferMultipleChoiceField(ModelMultipleChoiceField):
widget = OfferWidget
def __init__(self, *args, **kwargs):
super(OfferMultipleChoiceField, self).__init__(queryset=OfferItem.objects.all(), *args, **kwargs)
point is, the model/modelmultiple only makes sense if one adds the queryset, so there normally is one field per model...probably why the modelmultiple is not at all in the available fields.
the error might only occur with modelmultiplechoicefields, I couldnt check this yet.
adding forms.ModelMultipleChoiceField to *fields.MULTIPLE would help already, and then dealing with subclasses in the .is_a method even more.