Skip to content
Snippets Groups Projects
Verified Commit 28ef3bfc authored by Ernesto Rico Schmidt's avatar Ernesto Rico Schmidt
Browse files

fix: delete timeslots & schedule while deactivating a show

Closes: #180
parent a2efa413
No related branches found
No related tags found
No related merge requests found
Pipeline #7037 passed
......@@ -26,6 +26,7 @@ from versatileimagefield.fields import PPOIField, VersatileImageField
from django.contrib.auth.models import User
from django.db import models
from django.db.models import Q, QuerySet
from django.utils import timezone
from django.utils.translation import gettext_lazy as _
from program.utils import parse_datetime
from steering.settings import THUMBNAIL_SIZES
......@@ -248,6 +249,20 @@ class Show(models.Model):
def __str__(self):
return self.name
def save(self, *args, **kwargs):
now = timezone.datetime.now()
today = now.date()
if self.pk and self.is_active is False:
# deactivating a show means:
# - **delete all* the timeslots that belong to a schedule of this show the after now
# - **update all** the schedules of this show have today as `last_date`
TimeSlot.objects.filter(schedule__show=self, start__gt=now).delete()
self.schedules.filter(Q(last_date__gt=today) | Q(last_date=None)).update(
last_date=today
)
super().save(*args, **kwargs)
class ShowLink(Link):
show = models.ForeignKey(Show, on_delete=models.CASCADE, related_name="links")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment