I have a foreign key field called books (in the model Book) in an intermediate model called Link_Book_Courses.
I'd like to add multiple Book objects to thi开发者_StackOverflows. How do I do that in django?
Related Objects have an add() method:
https://docs.djangoproject.com/en/1.3/ref/models/relations/#django.db.models.fields.related.RelatedManager.add
You can add several like this
mymodel.related.add(*OtherModel.objects.filter(...))
For one ForeignKey you can only have one book. So to add multiple entries, you’ll have to add multiple Link_Book_Courses
-objects. However what you might really want is a ManyToManyField.
精彩评论