matches
This commit is contained in:
parent
8dcb5a8e31
commit
41a40de2d7
3 changed files with 21 additions and 2 deletions
|
@ -9,7 +9,6 @@ from django.contrib.auth.models import User, Group
|
|||
|
||||
import managers
|
||||
|
||||
|
||||
class Place(models.Model):
|
||||
'''
|
||||
Places are named locations, they should have geographical information attached to them.
|
||||
|
@ -69,6 +68,11 @@ class Place(models.Model):
|
|||
j[key] = getattr(self, key)
|
||||
return j
|
||||
|
||||
def update_matches(self):
|
||||
import random
|
||||
self.matches = random.randInt(0, 100)
|
||||
self.save()
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if not self.name_sort:
|
||||
self.name_sort = self.name #', '.join(self.name)
|
||||
|
|
13
pandora/place/tasks.py
Normal file
13
pandora/place/tasks.py
Normal file
|
@ -0,0 +1,13 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# vi:si:et:sw=4:sts=4:ts=4
|
||||
from datetime import timedelta
|
||||
|
||||
from celery.decorators import task, periodic_task
|
||||
|
||||
import models
|
||||
|
||||
|
||||
@task(ignore_resulsts=True, queue='default')
|
||||
def update_matches(id):
|
||||
place = models.Place.objects.get(pk=id)
|
||||
place.update_matches()
|
|
@ -14,7 +14,7 @@ from api.actions import actions
|
|||
from item import utils
|
||||
|
||||
import models
|
||||
|
||||
import tasks
|
||||
|
||||
@login_required_json
|
||||
def addPlace(request):
|
||||
|
@ -52,6 +52,7 @@ def addPlace(request):
|
|||
value = tuple(value)
|
||||
setattr(place, key, value)
|
||||
place.save()
|
||||
tasks.update_matches.delay(place.id)
|
||||
response = json_response(place.json())
|
||||
else:
|
||||
response = json_response(status=403, text='place name exists')
|
||||
|
@ -90,6 +91,7 @@ def editPlace(request):
|
|||
value = tuple(value)
|
||||
setattr(place, key, value)
|
||||
place.save()
|
||||
tasks.update_matches.delay(place.id)
|
||||
response = json_response(place.json())
|
||||
else:
|
||||
response = json_response(status=403, text='place name/geoname conflict')
|
||||
|
|
Loading…
Reference in a new issue