From c2ceb845dbef504de475bc18d7850266bc5eb636 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ses=C3=B3stris=20Vieira?= Date: Mon, 25 Sep 2023 09:59:35 -0300 Subject: [PATCH] =?UTF-8?q?Corrige=20bug=20na=20migra=C3=A7=C3=A3o=20dos?= =?UTF-8?q?=20banners=20dos=20eventos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../eventos/migrations/0045_alter_evento_banner.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/sigi/apps/eventos/migrations/0045_alter_evento_banner.py b/sigi/apps/eventos/migrations/0045_alter_evento_banner.py index 8179533..d260c07 100644 --- a/sigi/apps/eventos/migrations/0045_alter_evento_banner.py +++ b/sigi/apps/eventos/migrations/0045_alter_evento_banner.py @@ -11,9 +11,10 @@ def forwards(apps, schema_editor): for e in Evento.objects.exclude(banner="").exclude(banner=None): old_file = Path(e.banner.path) if old_file.exists(): - new_file = upload_to / e.banner.name - old_file.rename(new_file) - e.banner = str(new_file.resolve()) + new_file = upload_to / old_file.name + if not old_file.samefile(new_file): + old_file.rename(new_file) + e.banner = str(new_file.resolve()) else: e.banner = "" e.save() @@ -24,9 +25,10 @@ def backwards(apps, schema_editor): for e in Evento.objects.exclude(banner="").exclude(banner=None): new_file = Path(e.banner.path) if new_file.exists(): - old_file = settings.MEDIA_ROOT / e.banner.name - new_file.rename(old_file) - e.banner = str(old_file.resolve()) + old_file = settings.MEDIA_ROOT / new_file.name + if not old_file.samefile(new_file): + new_file.rename(old_file) + e.banner = str(old_file.resolve()) else: e.banner = "" e.save()