fixed merging issue
This commit is contained in:
parent
ac68fd30ae
commit
f085e7ff2f
@ -209,6 +209,8 @@ class OpenDataImporter:
|
|||||||
if obj['open_data_slug'] in existing_data or obj['name'] in existing_data_names:
|
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
|
# 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']:
|
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'])
|
source_obj = Food.objects.get(pk=existing_data[obj['open_data_slug']]['pk'])
|
||||||
del existing_data[obj['open_data_slug']]
|
del existing_data[obj['open_data_slug']]
|
||||||
source_obj.merge_into(Food.objects.get(pk=existing_data_names[obj['name']]['pk']))
|
source_obj.merge_into(Food.objects.get(pk=existing_data_names[obj['name']]['pk']))
|
||||||
|
@ -262,7 +262,9 @@ class MergeMixin(ViewSetMixin):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
if isinstance(source, Food):
|
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)]:
|
for link in [field for field in source._meta.get_fields() if issubclass(type(field), ForeignObjectRel)]:
|
||||||
linkManager = getattr(source, link.get_accessor_name())
|
linkManager = getattr(source, link.get_accessor_name())
|
||||||
|
Loading…
Reference in New Issue
Block a user