I have to models:
class A(Model):
b = models.ManyToManyField(B)
class B(Model):
# fields
What is the most efficient way to add a large number of existing instances of B to the relationship?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
As of django 1.4, you can make use of a
bulk_createmethod to create numerous B objects in one go, then add them to the A.bManyToManySo create a list of
Bobjects, bulk create them, then add them (all at once) to theManyToManyrelationship of yourAinstance(s):