food editor and property view improvements

This commit is contained in:
vabene1111
2023-05-24 13:49:29 +02:00
parent 79cd17a5ba
commit 3236b65d9e
7 changed files with 177 additions and 102 deletions

View File

@ -250,6 +250,9 @@ class MergeMixin(ViewSetMixin):
isTree = False
try:
if isinstance(source, Food):
FoodProperty.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())
related = linkManager.all()
@ -279,6 +282,7 @@ class MergeMixin(ViewSetMixin):
source.delete()
return Response(content, status=status.HTTP_200_OK)
except Exception:
traceback.print_exc()
content = {'error': True,
'msg': _(f'An error occurred attempting to merge {source.name} with {target.name}')}
return Response(content, status=status.HTTP_400_BAD_REQUEST)