From 3eafce808d8db149d5dde5f1942f7dd9c8b2f349 Mon Sep 17 00:00:00 2001 From: Ernesto Rico-Schmidt Date: Tue, 1 Nov 2011 15:51:26 +0100 Subject: made get_or_create_current more robust added MultipleObjectsReturned exception 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() -- cgit v0.10.2