Skip to content

Commit

Permalink
Make utils more generic
Browse files Browse the repository at this point in the history
  • Loading branch information
viggo-devries committed Dec 28, 2023
1 parent d9a25a4 commit 17f0684
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions oscar_odin/mappings/catalogue.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
save_attributes,
save_many_to_many,
save_one_to_many,
save_products,
save_objects,
save_foreign_keys,
)
from .context import ModelMapperContext
Expand Down Expand Up @@ -405,7 +405,7 @@ def products_to_db(
save_foreign_keys(context, errors)

# Save all the products in one go
save_products(instances, context, errors)
save_objects(ProductModel, instances, context, errors)

# Save all product attributes
save_attributes(instances)
Expand Down
8 changes: 4 additions & 4 deletions oscar_odin/mappings/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,18 @@ def save_foreign_keys(context, errors):
Model.objects.bulk_update(instances, fields=fields)


def save_products(instances, context, errors):
def save_objects(Model, instances, context, errors):
instances_to_create, instances_to_update = get_instances_to_create_or_update(
Product, instances, context.identifier_mapping
Model, instances, context.identifier_mapping
)

validated_create_instances, errors = validate_instances(instances_to_create, errors)

Product.objects.bulk_create(validated_create_instances)
Model.objects.bulk_create(validated_create_instances)

fields = context.get_fields_to_update(Product)
if fields is not None:
Product.objects.bulk_update(instances_to_update, fields=fields)
Model.objects.bulk_update(instances_to_update, fields=fields)


def save_one_to_many(context, errors):
Expand Down

0 comments on commit 17f0684

Please sign in to comment.