1👍
✅
You are getting this error because you are passing a text string to be used as the nomTreballador
foreign key, while you should be passing a treballador
instance.
It looks like you’re trying to restrict the available choices to a set of distinct trebellador
s by using a forms.ChoiceField
, but a better way to do this with a ModelForm is to change the queryset
attribute of the nomTreballador
field. You do this in the form’s init
method:
self.fields['nomTreballador'].queryset = treballador.objects.all().distinct()
Also you should check the clean
methods you’ve implemented because not all of them map to an existing field.
Source:stackexchange.com