How to save id from another model using choicefield?

107 views Asked by At

I have a ModelMultipleChoicefield and a queryset with another model.

NamesModel contains only names and id

ID_model contains only id of NamesModel

class MyCreateForm(forms.ModelForm):
    my_id = forms.ModelMultipleChoiceField(queryset=NamesModel.objects.all())

    class Meta:
        model = ID_model

When rendering form I can choose names for example. 'Adam', John'.

My problem is I want my form to display NamesModel, but save NamesModel id to my_id.

How can I do that?

0

There are 0 answers