Browse Source

Corrige o path de upload dos banners dos eventos

pull/166/head 3.0.49
Sesóstris Vieira 1 year ago
parent
commit
379707e7b6
  1. 56
      sigi/apps/eventos/migrations/0045_alter_evento_banner.py
  2. 6
      sigi/apps/eventos/models.py

56
sigi/apps/eventos/migrations/0045_alter_evento_banner.py

@ -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),
]

6
sigi/apps/eventos/models.py

@ -458,7 +458,11 @@ class Evento(models.Model):
blank=True, blank=True,
help_text=_("telefone da pessoa de contato na casa anfitriã"), help_text=_("telefone da pessoa de contato na casa anfitriã"),
) )
banner = models.ImageField(_("banner do evento"), blank=True, null=True) banner = models.ImageField(
_("banner do evento"),
blank=True,
upload_to="apps/eventos/evento/banner/",
)
data_cancelamento = models.DateField( data_cancelamento = models.DateField(
_("Data de cancelamento"), blank=True, null=True _("Data de cancelamento"), blank=True, null=True
) )

Loading…
Cancel
Save