events and places
This commit is contained in:
parent
ce8656ef53
commit
6f0393d12c
4 changed files with 150 additions and 23 deletions
|
|
@ -20,6 +20,7 @@ def parseCondition(condition, user):
|
|||
k = {
|
||||
'user': 'user__username',
|
||||
'place': 'places__id',
|
||||
'event': 'events__id',
|
||||
}.get(k, k)
|
||||
if not k:
|
||||
k = 'name'
|
||||
|
|
@ -41,12 +42,12 @@ def parseCondition(condition, user):
|
|||
return q
|
||||
if k == 'id':
|
||||
v = ox.from32(v.split('/')[-1])
|
||||
elif k in ('places__id', ):
|
||||
elif k in ('places__id', 'events__id'):
|
||||
v = ox.from32(v)
|
||||
if isinstance(v, bool): #featured and public flag
|
||||
key = k
|
||||
elif k in ('lat', 'lng', 'area', 'south', 'west', 'north', 'east', 'matches',
|
||||
'id', 'places__id'):
|
||||
'id', 'places__id', 'events__id'):
|
||||
key = "%s%s" % (k, {
|
||||
'>': '__gt',
|
||||
'>=': '__gte',
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@ class Event(models.Model):
|
|||
|
||||
matches = models.IntegerField(default=0)
|
||||
items = models.ManyToManyField(Item, blank=True, related_name='events')
|
||||
annotations = models.ManyToManyField(Annotation, blank=True, related_name='events')
|
||||
|
||||
def __unicode__(self):
|
||||
return self.name
|
||||
|
|
@ -64,6 +65,10 @@ class Event(models.Model):
|
|||
def update_matches(self):
|
||||
matches = self.get_matches()
|
||||
self.matches = matches.count()
|
||||
for i in self.annotations.exclude(id__in=matches):
|
||||
self.annotations.remove(i)
|
||||
for i in matches.exclude(id__in=self.annotations.all()):
|
||||
self.annotations.add(i)
|
||||
ids = list(set([a.item.id for a in matches]))
|
||||
for i in self.items.exclude(id__in=ids):
|
||||
self.items.remove(i)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue