[Answer]-Inserting a foreign field in django forms

1👍

By your Form definition taxonomy and author are IntergerField. The dict you copied set QuerySet as value in your form, which is obvious not a number.

Why did you choose to overwrite the fields in the ModelForm? Do you want to your users to type the id of the object instead of using a select? Because in that case I would just overwrite the widgets within Meta.

class DatasetForm(forms.ModelForm):
    class Meta:
        model = Dataset
        fields = ('dataset_id','title','taxonomy','citation','summary','contributor','submitted','last_updated','author')
        widgets = {
            'taxonomy': forms.NumberInput,
            'author': forms.NumberInput,
        }

More info: https://docs.djangoproject.com/en/1.8/topics/forms/modelforms/#overriding-the-default-fields

Leave a comment