def bulk_create(self, objs, batch_size=None):
<EOL><INDENT>assert batch_size is None or batch_size > <NUM_LIT:0><EOL>if self.model._meta.parents:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if not objs:<EOL><INDENT>return objs<EOL><DEDENT>self._for_write = True<EOL>connection = connections[self.db]<EOL>fields = self.model._meta.local_fields<EOL>if not transaction.is_managed(using=self.db):<EOL><INDENT>transaction.enter_transaction_management(using=self.db)<EOL>forced_managed = True<EOL><DEDENT>else:<EOL><INDENT>forced_managed = False<EOL><DEDENT>try:<EOL><INDENT>if (connection.features.can_combine_inserts_with_and_without_auto_increment_pk<EOL>and self.model._meta.has_auto_field):<EOL><INDENT>self._batched_insert(objs, fields, batch_size)<EOL><DEDENT>else:<EOL><INDENT>objs_with_pk, objs_without_pk = partition(lambda o: o.pk is None, objs)<EOL>if objs_with_pk:<EOL><INDENT>self._batched_insert(objs_with_pk, fields, batch_size)<EOL><DEDENT>if objs_without_pk:<EOL><INDENT>fields= [f for f in fields if not isinstance(f, AutoField)]<EOL>self._batched_insert(objs_without_pk, fields, batch_size)<EOL><DEDENT><DEDENT>if forced_managed:<EOL><INDENT>transaction.commit(using=self.db)<EOL><DEDENT>else:<EOL><INDENT>transaction.commit_unless_managed(using=self.db)<EOL><DEDENT><DEDENT>finally:<EOL><INDENT>if forced_managed:<EOL><INDENT>transaction.leave_transaction_management(using=self.db)<EOL><DEDENT><DEDENT>return objs<EOL><DEDENT>raise NotImplementedError()<EOL>
Inserts each of the instances into the database. This does *not* call
save() on each of the instances, does not send any pre/post save
signals, and does not set the primary key attribute if it is an
autoincrement field.