django-forms-builder icon indicating copy to clipboard operation
django-forms-builder copied to clipboard

custom ModelMultipleChoiceField, initial values

Open benzkji opened this issue 10 years ago • 4 comments

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?

benzkji avatar Aug 07 '14 07:08 benzkji

couldn't there be a check if the field inherits from a multiple base field, so the MULTIPLEwould be obsolete?

benzkji avatar Aug 11 '14 11:08 benzkji

Can you provide the code needed to reproduce your example?

stephenmcd avatar Aug 14 '14 22:08 stephenmcd

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.

benzkji avatar Aug 14 '14 22:08 benzkji

adding forms.ModelMultipleChoiceField to *fields.MULTIPLE would help already, and then dealing with subclasses in the .is_a method even more.

benzkji avatar Aug 14 '14 22:08 benzkji