diff --git a/cookbook/helper/open_data_importer.py b/cookbook/helper/open_data_importer.py index c032f37c..e598d3fd 100644 --- a/cookbook/helper/open_data_importer.py +++ b/cookbook/helper/open_data_importer.py @@ -209,6 +209,8 @@ class OpenDataImporter: if obj['open_data_slug'] in existing_data or obj['name'] in existing_data_names: # rather rare edge cases object A has the slug and object B has the name which would lead to uniqueness errors if obj['open_data_slug'] in existing_data and obj['name'] in existing_data_names and existing_data[obj['open_data_slug']]['pk'] != existing_data_names[obj['name']]['pk']: + # TODO this fails if objects are parent/children of a tree + # TODO this does not merge nicely (with data), write better merge method (or use generalized one if available when reading this) source_obj = Food.objects.get(pk=existing_data[obj['open_data_slug']]['pk']) del existing_data[obj['open_data_slug']] source_obj.merge_into(Food.objects.get(pk=existing_data_names[obj['name']]['pk'])) diff --git a/cookbook/views/api.py b/cookbook/views/api.py index eb2523f8..1173d747 100644 --- a/cookbook/views/api.py +++ b/cookbook/views/api.py @@ -262,7 +262,9 @@ class MergeMixin(ViewSetMixin): try: if isinstance(source, Food): - source.properties.remove() + source.properties.all().delete() + source.properties.clear() + UnitConversion.objects.filter(food=source).delete() for link in [field for field in source._meta.get_fields() if issubclass(type(field), ForeignObjectRel)]: linkManager = getattr(source, link.get_accessor_name())