0

I want to show different fields (a html-option-field who gets Mymodel.object.all and a textfield) and save it to one model field.

How can I build this?

MultiValueField (https://docs.djangoproject.com/en/2.1/ref/forms/fields/) doesn't help with different fields? Has someone an example? How can I define which kind of field it is?

EDIT: How can I determine which field I want to save in the model-field? I use a ModelForm.

1 Answer 1

1

You should use forms.ModelChoiceField(choices=ModelClass.objects.all()) for the choicefield, you can also set the widget to be widget=forms.CheckboxSelectMultiple.

your form can be like

class SuperForm(forms.Form):
    cool_field = forms.ModelChoiceField(
        choices=ModelClass.objects.all(),
        widget=forms.CheckboxSelectMultiple,
    )

    text_area = forms.CharField(widget=forms.Textarea)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.