Form that saves data into multiple models
Hello,
I have 2 models: car and salesman. I want to make a form based off the car model. Salesman name is a foreign key in the car model. In the form, I want to be able to enter the salesman's name and if it doesn't exist already then create a new salesman.
So I have something like this in forms.py
class Car(forms.ModelForm):
salesman_name = forms.CharField()
class Meta:
model = Car
But when I enter something into the salesman_name field it errors:
Cannot assign "u'x'": "Salesman.name" must be a "Salesman" instance.
How do I override that? So that it creates a new salesman when the entered one doesn't match a current one?
Thank you,
Lev
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home