diff options
Diffstat (limited to 'db.py')
-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): |