mirror of https://github.com/interlegis/sigi.git
Sesóstris Vieira
1 year ago
2 changed files with 61 additions and 1 deletions
@ -0,0 +1,56 @@ |
|||
# Generated by Django 4.2.4 on 2023-09-21 14:00 |
|||
from pathlib import Path |
|||
from django.db import migrations, models |
|||
from django.conf import settings |
|||
|
|||
upload_to = settings.MEDIA_ROOT / "apps/eventos/evento/banner/" |
|||
|
|||
|
|||
def forwards(apps, schema_editor): |
|||
Evento = apps.get_model("eventos", "Evento") |
|||
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()) |
|||
else: |
|||
e.banner = "" |
|||
e.save() |
|||
|
|||
|
|||
def backwards(apps, schema_editor): |
|||
Evento = apps.get_model("eventos", "Evento") |
|||
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()) |
|||
else: |
|||
e.banner = "" |
|||
e.save() |
|||
|
|||
|
|||
class Migration(migrations.Migration): |
|||
dependencies = [ |
|||
( |
|||
"eventos", |
|||
"0044_evento_chave_inscricao_evento_contato_inscricao_and_more", |
|||
), |
|||
] |
|||
|
|||
operations = [ |
|||
migrations.AlterField( |
|||
model_name="evento", |
|||
name="banner", |
|||
field=models.ImageField( |
|||
blank=True, |
|||
default="", |
|||
upload_to="apps/eventos/evento/banner/", |
|||
verbose_name="banner do evento", |
|||
), |
|||
preserve_default=False, |
|||
), |
|||
migrations.RunPython(forwards, backwards), |
|||
] |
Loading…
Reference in new issue