support id in query

This commit is contained in:
j 2011-10-18 22:05:11 +02:00
parent 778639def8
commit 767176fa09

View file

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