Skip to content

Commit

Permalink
Delete EventAreaStatistics for test event areas
Browse files Browse the repository at this point in the history
  • Loading branch information
juuso-j committed Jun 6, 2024
1 parent 42ce5f6 commit a0e289b
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions parkings/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
from math import ceil

from django.db import transaction
from django.db.models.signals import post_delete, post_save
from django.db.models.signals import post_delete, post_save, pre_delete
from django.dispatch import receiver
from django.utils import timezone

from parkings.models import EventParking
from parkings.models import EventArea, EventAreaStatistics, EventParking


@transaction.atomic
Expand Down Expand Up @@ -42,3 +42,11 @@ def event_parking_on_save(sender, **kwargs):
def event_parking_on_delete(sender, **kwargs):
obj = kwargs["instance"]
update_statistics(obj.event_area)


@receiver(pre_delete, sender=EventArea)
def event_area_on_delete(sender, **kwargs):
obj = kwargs["instance"]
# Only test event areas can be deleted.
if obj.is_test:
EventAreaStatistics.objects.filter(event_area=obj).delete()

0 comments on commit a0e289b

Please sign in to comment.