summaryrefslogtreecommitdiff
path: root/program
diff options
context:
space:
mode:
authorErnesto Rico-Schmidt <e.rico.schmidt@gmail.com>2011-11-01 14:51:26 (GMT)
committerErnesto Rico-Schmidt <e.rico.schmidt@gmail.com>2011-11-01 14:51:26 (GMT)
commit3eafce808d8db149d5dde5f1942f7dd9c8b2f349 (patch)
tree6a52df6d1aa9353ad24a5f66488ffcef47285466 /program
parentc4f7faf65485df31299e137fd4e2eb596b1c84be (diff)
made get_or_create_current more robust
added MultipleObjectsReturned exception
Diffstat (limited to 'program')
-rw-r--r--program/models.py4
1 files changed, 3 insertions, 1 deletions
diff --git a/program/models.py b/program/models.py
index eed5ac1..ee881bc 100644
--- a/program/models.py
+++ b/program/models.py
@@ -1,5 +1,5 @@
from django.contrib.auth.models import User
-from django.core.exceptions import ObjectDoesNotExist, ValidationError
+from django.core.exceptions import ObjectDoesNotExist, ValidationError, MultipleObjectsReturned
from django.db import models
from django.utils.translation import ugettext_lazy as _
@@ -232,6 +232,8 @@ class TimeSlotManager(models.Manager):
def get_or_create_current(self):
try:
return TimeSlot.objects.get(start__lte=datetime.now(), end__gt=datetime.now())
+ except MultipleObjectsReturned:
+ return TimeSlot.objects.filter(start__lte=datetime.now(), end__gt=datetime.now())[0]
except ObjectDoesNotExist:
once = RRule.objects.get(pk=1)
today = date.today().weekday()