Reputation: 53
Models:
class Author(models.Model):
name = models.CharField(max_length=150)
age = models.IntegerField()
class Book(models.Model):
title = models.CharField(max_length=150)
number = models.IntegerField()
author = models.ManyToManyField(Author)
Goal:
http://feb.imghost.us/HaAo.png
How can I create this form? (should allow to add many Authors before I save whole form)
Upvotes: 0
Views: 303
Reputation: 387
Say you have a book with mulitple authors, You want to save multiple authors to same book object, if that is the case when user adds the author save the author object and use jquery to save the newly created author object id in a hidden field ( create a hidden input tag with author id) and when user saves the book retrieve all the hidden author ids and save the book with the authors.
Upvotes: 1