Re: How do I save records when using two forms joined by a foreign key?

2008-06-25 Thread Huuuze
Found the answer why BookForm wasn't validating. I needed to "exclude" the author field from BookForm. As soon as I did that, everything fell into place. Quick debugging tip for Django n00bs: I established that the missing author was the problem by executing this line of code: >> print

Re: How do I save records when using two forms joined by a foreign key?

2008-06-25 Thread Huuuze
Thanks for the tip. I've now run into another issue. My book isn't validating. Is there a quick way to figure out what field(s) are causing this error: The Book could not be created because the data didn't validate. On Jun 25, 6:10 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > What

Re: How do I save records when using two forms joined by a foreign key?

2008-06-25 Thread [EMAIL PROTECTED]
What you would do is: book_form = BookForm(request.POST) book = book_form.save(commit=False) book.author = author book.save() what save(commit=False) does, is create a model instance with the data from the form, but doesn't save it to the db, then you can handle it like a regular model. On Jun

How do I save records when using two forms joined by a foreign key?

2008-06-25 Thread Huuuze
For the sake of argument, I have two models: Book and Author. Book has many fields and has a foreign key relationship with Author. Author has two fields and no additional relationships. To stay DRY, I have BookForm and AuthorForm classes that I use to generate the HTML for each class. When I