mirror of
https://github.com/fergalmoran/dss.api.git
synced 2025-12-31 21:59:05 +00:00
30 lines
905 B
Python
Executable File
30 lines
905 B
Python
Executable File
from django.db import models
|
|
from django.db.models import Q, ForeignKey
|
|
# from schedule.models import Event
|
|
from spa.models.mix import Mix
|
|
from spa.models.basemodel import BaseModel
|
|
|
|
|
|
class ShowOverlapException(Exception):
|
|
pass
|
|
|
|
|
|
class Show(BaseModel): # Event):
|
|
mix = ForeignKey(Mix, related_name='show')
|
|
test_field = models.CharField(max_length=400)
|
|
|
|
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)
|