only get director, year and director if director was passed in query

This commit is contained in:
j 2013-02-28 15:45:50 +05:30
parent 055717d461
commit d712ff043f
2 changed files with 6 additions and 3 deletions

View file

@ -249,7 +249,11 @@ class Match(models.Model):
'director': ';'.join(sorted(data.get('director', []))) 'director': ';'.join(sorted(data.get('director', [])))
} }
keys = [] keys = []
for k in cls.keys: if not data['director']:
_keys = [k for k in cls.keys if k not in (['director', 'year'], ['director'])]
else:
_keys = cls.keys
for k in _keys:
key = '\0'.join(k) key = '\0'.join(k)
value = '\0'.join([data[v] for v in k]) value = '\0'.join([data[v] for v in k])
if isinstance(value, unicode): if isinstance(value, unicode):
@ -265,7 +269,7 @@ class Match(models.Model):
matches = [] matches = []
items = [] items = []
for key in cls.get_keys(data): for key in cls.get_keys(data):
for m in cls.objects.filter(key=key).order_by('item__imdb'): for m in cls.objects.filter(key=key).order_by('item__imdb').select_related():
if m.item.id not in items: if m.item.id not in items:
matches.append(m.json()) matches.append(m.json())
items.append(m.item.id) items.append(m.item.id)

View file

@ -29,7 +29,6 @@ def getIds(request):
return render_to_json_response(response) return render_to_json_response(response)
actions.register(getIds) actions.register(getIds)
def getData(request): def getData(request):
response = json_response() response = json_response()
data = json.loads(request.POST['data']) data = json.loads(request.POST['data'])