Wednesday, October 20, 2021

Modeform Foreign key column not working

Hi,

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 django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f5145780-1a87-451a-a0a3-8f100527499an%40googlegroups.com.

No comments:

Post a Comment