From 767176fa0990ab62bd8b12e47f0172b698eec101 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Tue, 18 Oct 2011 22:05:11 +0200 Subject: [PATCH] support id in query --- oxdata/movie/models.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/oxdata/movie/models.py b/oxdata/movie/models.py index aaa0564..321822e 100644 --- a/oxdata/movie/models.py +++ b/oxdata/movie/models.py @@ -9,18 +9,21 @@ import ox def find(info, guess=True): q = Imdb.objects.all() - if 'seriesTitle' in info: - info['title'] = info['seriesTitle'] - for key in Imdb.keys: - if key in info and info[key]: - if isinstance(info[key], basestring): - fkey = '%s__iexact'%key - else: - fkey = key - if isinstance(info[key], list): - q = q.filter(**{fkey: '\n'.join(info[key]) + '\n'}) - else: - q = q.filter(**{fkey:info[key]}) + if 'id' in info: + q = q.filter(imdb=info['id']) + else: + if 'seriesTitle' in info: + info['title'] = info['seriesTitle'] + for key in Imdb.keys: + if key in info and info[key]: + if isinstance(info[key], basestring): + fkey = '%s__iexact'%key + else: + fkey = key + if isinstance(info[key], list): + q = q.filter(**{fkey: '\n'.join(info[key]) + '\n'}) + else: + q = q.filter(**{fkey:info[key]}) if q.count() == 1: return q[0] #For now fallback to ox.web.imdb.guess and try again