From 0a98e4a7784fb810be848f2a387101c135c97ab3 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Fri, 1 Jun 2018 20:36:23 +0200 Subject: [PATCH] Fix error in auto_delete_photo_on_change --- recette/models.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/recette/models.py b/recette/models.py index aac7568..feb3468 100644 --- a/recette/models.py +++ b/recette/models.py @@ -96,7 +96,5 @@ def auto_delete_photo_on_change(sender, instance, **kwargs): except Recette.DoesNotExist: return False - new_file = instance.photo - if not old_file == new_file: - if os.path.isfile(old_file.path): - os.remove(old_file.path) + if old_file and old_file != instance.photo and os.path.isfile(old_file.path): + os.remove(old_file.path)