Skip to content

Commit

Permalink
made QuerySet.bulk_create() set pk on created model instances
Browse files Browse the repository at this point in the history
  • Loading branch information
timgraham committed Dec 12, 2024
1 parent c098777 commit 546554a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions django_mongodb/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,13 +677,13 @@ def execute_sql(self, returning_fields=None):

field_values[field.column] = value
objs.append(field_values)
return [self.insert(objs, returning_fields=returning_fields)]
return self.insert(objs, returning_fields=returning_fields)

@wrap_database_errors
def insert(self, docs, returning_fields=None):
"""Store a list of documents using field columns as element names."""
inserted_ids = self.collection.insert_many(docs).inserted_ids
return inserted_ids if returning_fields else []
return [(x,) for x in inserted_ids] if returning_fields else []

@cached_property
def collection_name(self):
Expand Down
1 change: 1 addition & 0 deletions django_mongodb/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class DatabaseFeatures(BaseDatabaseFeatures):
allows_multiple_constraints_on_same_fields = False
can_create_inline_fk = False
can_introspect_foreign_keys = False
can_return_rows_from_bulk_insert = True
greatest_least_ignores_nulls = True
has_json_object_function = False
has_native_json_field = True
Expand Down

0 comments on commit 546554a

Please sign in to comment.