Thursday, October 21, 2021

Re: Modeform Foreign key column not working

yeah, it is a foreign key and I have put integer field instead of foreign key in the model. I changed it now and its working by itself without specifying ModelChoiceField. 

Thanks for your help!! 

On Wednesday, 20 October 2021 at 16:07:04 UTC+1 wrote:
is `ConnectionTypes` a foreign key to `ConnectionDetails`?
in that case you don't need to put it as a field in form, it will be added automatically in the form. 
On Wednesday, 20 October 2021 at 18:47:44 UTC+5:30 Aruna Priya wrote:

I am trying to create a form from model and the model has a foreign key and am not able to populate the values from the column it refers to.

My form,

class ConnectionForm(forms.ModelForm):
 connection_type = forms.ModelChoiceField(queryset=ConnectionTypes.objects.all(), to_field_name='connection_type_id')

    class Meta:
        model = ConnectionDetails
        exclude = ['connection_id','last_update_date']

You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit

No comments:

Post a Comment