event matches

This commit is contained in:
j 2011-06-04 17:44:29 +02:00
parent 78321d2f9a
commit a734c0b821

View file

@ -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