How do I add several books to the bookstore in the admin form
<p>In django, imagine i have a model bookstore and a model book which has a foreign key to bookStore model . On the django admin,I added like 10 books, and on the bookstore I want to assign multiple books to this one bookstore. How do I do this ? Because even with foreignKey, while editing the bookstore, i can only choose one book...</p>

<pre><code>class BookStore(models.Model):
    name = models.CharField(max_length=100)

class Book(models.Model):
    name = models.CharField(max_length=100)
    store = models.ForeignKey(BookStore, null=True)
</code></pre>

<p>Your relationship is the wrong way around. If your bookstore has a fk to a book, you are saying that "each bookstore can only store one single book". Instead, you should have a fk from the book to the book store. This is saying "a book belongs to a bookstore (and only one bookstore)"</p>

<pre><code>class Book:
    bookstore = models.ForeignKey("Bookstore")

class Bookstore:
    ...
</code></pre>

<p>You need to use an <a href="https://docs.djangoproject.com/en/1.10/ref/contrib/admin/#inlinemodeladmin-objects" rel="nofollow">inline form</a> if you want to add multiple books while editing your bookstore object: </p>

<pre><code>class BookInline(admin.StackedInline):
    model = Book

class BookstoreAdmin(admin.ModelAdmin): 
    model = Bookstore
    inlines = [BookInline,]
</code></pre>

python django