git.ithinksw.org
/
philo.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
fb2124a
)
Added some convenient methods to event querysets.
author
Harris Lapiroff
<hlapirof@oberlin.edu>
Wed, 23 Mar 2011 17:24:12 +0000
(13:24 -0400)
committer
Harris Lapiroff
<hlapirof@oberlin.edu>
Wed, 23 Mar 2011 17:24:12 +0000
(13:24 -0400)
contrib/julian/models.py
patch
|
blob
|
history
diff --git
a/contrib/julian/models.py
b/contrib/julian/models.py
index
3ec97b0
..
44b51f6
100644
(file)
--- 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.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
from django.http import HttpResponse, Http404
from django.utils.encoding import force_unicode
from philo.contrib.julian.feedgenerator import ICalendarFeed
@@
-73,6
+74,10
@@
class TimedModel(models.Model):
abstract = True
abstract = True
+class EventManager(models.Manager):
+ def get_query_set(self):
+ return self.model.QuerySet(self.model)
+
class Event(Entity, TimedModel):
name = models.CharField(max_length=255)
slug = models.SlugField(max_length=255, unique_for_date='start_date')
class Event(Entity, TimedModel):
name = models.CharField(max_length=255)
slug = models.SlugField(max_length=255, unique_for_date='start_date')
@@
-94,6
+99,22
@@
class Event(Entity, TimedModel):
last_modified = models.DateTimeField(auto_now=True)
uuid = models.TextField() # Format?
last_modified = models.DateTimeField(auto_now=True)
uuid = models.TextField() # Format?
+ objects = EventManager()
+
+ class QuerySet(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'))
+
def __unicode__(self):
return self.name
def __unicode__(self):
return self.name