default shotgun for existing rows

This commit is contained in:
Ludovic Stephan 2016-12-21 01:05:04 -02:00
parent e8be072e78
commit 2f70dbf911

View file

@ -2,6 +2,19 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from django.db import models, migrations from django.db import models, migrations
from django.utils import timezone
from datetime import timedelta
def forwards_func(apps, schema_editor):
SpectacleRevente = apps.get_model("bda", "SpectacleRevente")
for revente in SpectacleRevente.objects.all():
is_expired = timezone.now() > revente.date_tirage()
is_direct = (revente.attribution.spectacle.date >= revente.date and
timezone.now() > revente.date + timedelta(minutes=15))
revente.shotgun = is_expired or is_direct
revente.save()
class Migration(migrations.Migration): class Migration(migrations.Migration):
@ -16,4 +29,5 @@ class Migration(migrations.Migration):
name='shotgun', name='shotgun',
field=models.BooleanField(default=False, verbose_name='Disponible imm\xe9diatement'), field=models.BooleanField(default=False, verbose_name='Disponible imm\xe9diatement'),
), ),
migrations.RunPython(forwards_func, migrations.RunPython.noop),
] ]