diff options
author | Jon Bergli Heier <snakebite@jvnv.net> | 2011-08-23 23:24:16 +0200 |
---|---|---|
committer | Jon Bergli Heier <snakebite@jvnv.net> | 2011-08-23 23:24:16 +0200 |
commit | f48773661a235864a8460e1ca0810f0593ac93be (patch) | |
tree | 78f2474f06f923a381b610fc4ecc78a3c8cc7e54 | |
parent | 8f1b87a29af1526c6adbb16694dbb52aa8cce26e (diff) |
Fixed search.
-rw-r--r-- | db.py | 11 |
1 files changed, 8 insertions, 3 deletions
@@ -8,7 +8,7 @@ Base = declarative_base() from sqlalchemy import Column, Integer, String, ForeignKey from sqlalchemy.orm import relationship, backref -from sqlalchemy import and_ +from sqlalchemy import and_, or_ from sqlalchemy.orm.exc import NoResultFound @@ -132,11 +132,16 @@ class Track(Base): @staticmethod def search(session, *args, **kwargs): r = session.query(Track) + s_or = [] for f, n in ((Artist, 'artist'), (Track, 'title'), (Album, 'album')): + if f != Track: + r = r.join(f) if n in kwargs: - if f != Track: - r = r.join(f) r = r.filter(f.name.ilike('%{0}%'.format(kwargs[n]))) + for i in args: + s_or.append(f.name.ilike('%{0}%'.format(i))) + if len(s_or): + r = r.filter(or_(*s_or)) return r.all() def get_path(self): |