I am just banging my head against the wall and making no progress with this issue.

I am trying to create a view that nests forms of related models. I had thought that inlineformset_factory would do the trick, but I clearly don't understand something.

Assume I have the following models:

<snip>
class Author(models.Model):
    name = models.CharField(max_length=100)

class Book(models.Model):
    author = models.ForeignKey(Author)
    title = models.CharField(max_length=100)
</snip>

And the following forms:

<snip>
class AuthorForm(forms.ModelForm):
    class Meta:
        model = Author

class BookForm(forms.ModelForm):
    class Meta:
        model = Book

BookInlineFormSet = inlineformset_factory(Author, Book)
</snip>

Now assume I want to create a view that lets me create a new books, along with a new author. According to various documentation, I ought to do something a bit like this:

<snip>
def new_author(request):
  authorForm = AuthorForm()
  author = Author() # an empty author
bookFormSet = BookInlineFormSet(instance=author) # since author is empty, shouldn't this contain empty forms?
  return render_to_response("new_author.html", {"formset" : bookFormSet, })
</snip>

But all I get is a set of fields belonging to the BookForm ("title") and nothing from the AuthorForm ("name").

Any advice?

Thanks for your help.


--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to