From 1db636d8c1e06e6234f5730d86ccc48ba811b65f Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Sat, 4 Jun 2011 17:44:29 +0200 Subject: [PATCH] event matches --- pandora/event/models.py | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/pandora/event/models.py b/pandora/event/models.py index 5333faf2f..7d203ac0a 100644 --- a/pandora/event/models.py +++ b/pandora/event/models.py @@ -4,10 +4,12 @@ from __future__ import division, with_statement from django.db import models from django.contrib.auth.models import User, Group +from django.db.models import Q import ox from ox.django import fields +from annotation.models import Annotation import managers @@ -34,12 +36,28 @@ class Event(models.Model): ordering = ('name_sort', ) #start yyyy-mm-dd|mm-dd|dow 00:00|00:00 - #end yyyy-mm-dd|mm-dd|dow 00:00|00:01 start = models.CharField(default='', max_length=255) - end = models.CharField(default='', max_length=255) startTime = models.BigIntegerField(default=0) + + #end yyyy-mm-dd|mm-dd|dow 00:00|00:01 + end = models.CharField(default='', max_length=255) endTime = models.BigIntegerField(default=0) + + duration = models.CharField(default='', max_length=255) + durationTime = models.BigIntegerField(default=0) + type = models.CharField(default='', max_length=255) + matches = models.IntegerField(default=0) + + def get_matches(self): + q = Q(value__icontains=" " + self.name)|Q(value__startswith=self.name) + for name in self.alternativeNames: + q = q|Q(value__icontains=" " + name)|Q(value__startswith=name) + return Annotation.objects.filter(q) + + def update_matches(self): + self.matches = self.get_matches().count() + self.save() def save(self, *args, **kwargs): if not self.name_sort: @@ -56,7 +74,8 @@ class Event(models.Model): 'user': self.user.username, } for key in ('created', 'modified', - 'name', 'alternativeNames', 'start', 'end', - 'type'): + 'name', 'alternativeNames', + 'start', 'end', 'duration', + 'type', 'matches'): j[key] = getattr(self, key) return j