From: Stephen Burrows Date: Mon, 28 Mar 2011 21:16:24 +0000 (-0400) Subject: Merge branch 'julian' of git://github.com/lapilofu/philo X-Git-Tag: philo-0.9~16^2~6 X-Git-Url: http://git.ithinksw.org/philo.git/commitdiff_plain/e14041301b4d914127920f50e47a9ae8c990af4e?hp=93249b4cb9fec0fc8e0d2fd2eff669e9f3704033 Merge branch 'julian' of git://github.com/lapilofu/philo --- diff --git a/contrib/julian/models.py b/contrib/julian/models.py index 3ec97b0..333bcb3 100644 --- a/contrib/julian/models.py +++ b/contrib/julian/models.py @@ -6,6 +6,7 @@ from django.contrib.contenttypes.models import ContentType from django.core.exceptions import ValidationError, ObjectDoesNotExist from django.core.validators import RegexValidator from django.db import models +from django.db.models.query import QuerySet from django.http import HttpResponse, Http404 from django.utils.encoding import force_unicode from philo.contrib.julian.feedgenerator import ICalendarFeed @@ -73,6 +74,20 @@ class TimedModel(models.Model): abstract = True +class EventManager(models.Manager): + def get_query_set(self): + return EventQuerySet(self.model) + +class EventQuerySet(QuerySet): + def upcoming(self): + return self.filter(start_date__gte=datetime.date.today()) + def current(self): + return self.filter(start_date__lte=datetime.date.today(), end_date__gte=datetime.date.today()) + def single_day(self): + return self.filter(start_date__exact=models.F('end_date')) + def multiday(self): + return self.exclude(start_date__exact=models.F('end_date')) + class Event(Entity, TimedModel): name = models.CharField(max_length=255) slug = models.SlugField(max_length=255, unique_for_date='start_date') @@ -94,6 +109,8 @@ class Event(Entity, TimedModel): last_modified = models.DateTimeField(auto_now=True) uuid = models.TextField() # Format? + objects = EventManager() + def __unicode__(self): return self.name