mirror of
https://github.com/fergalmoran/dss.git
synced 2026-01-18 06:44:01 +00:00
29 lines
788 B
Python
29 lines
788 B
Python
from django.db.models import Q, ForeignKey
|
|
from schedule.models import Event
|
|
from spa.models import Mix
|
|
|
|
|
|
class ShowOverlapException(Exception):
|
|
pass
|
|
|
|
|
|
class Show(Event):
|
|
mix = ForeignKey(Mix, related_name='show')
|
|
|
|
class Meta:
|
|
app_label = 'spa'
|
|
|
|
def save(self, force_insert=False, force_update=False, using=None,
|
|
update_fields=None):
|
|
"""
|
|
throw an exception if event overlaps with another event
|
|
"""
|
|
overlaps = Show.objects.filter(
|
|
Q(start__gte=self.start, end__lte=self.start) |
|
|
Q(start__gte=self.end, end__lte=self.end)
|
|
)
|
|
if len(overlaps) != 0:
|
|
raise ShowOverlapException()
|
|
|
|
return super(Show, self).save(force_insert, force_update, using, update_fields)
|