summaryrefslogtreecommitdiff
path: root/db.py
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2011-08-23 18:15:26 +0200
committerJon Bergli Heier <snakebite@jvnv.net>2011-08-23 18:15:26 +0200
commit914761368f6a5f19df26019e8290b4e86fb76cfb (patch)
treecf479451cec2e109889f077ffaf7549d019e2b0e /db.py
parentc8754366695abe10364963f1fe0c82dad5987102 (diff)
Implemented simple search.
Diffstat (limited to 'db.py')
-rw-r--r--db.py12
1 files changed, 11 insertions, 1 deletions
diff --git a/db.py b/db.py
index 1f68711..ac73a47 100644
--- a/db.py
+++ b/db.py
@@ -100,7 +100,7 @@ class Track(Base):
album_id = Column(Integer, ForeignKey('albums.id'))
directory = relationship(Directory, backref = backref('tracks', order_by = filename))
- artist = relationship(Artist, backref = backref('artists'))
+ artist = relationship(Artist, backref = backref('tracks'))
album = relationship(Album, backref = backref('tracks'))
def __init__(self, name, num, filename, file_index, directory_id, artist_id, album_id):
@@ -129,6 +129,16 @@ class Track(Base):
directory, filename = os.path.split(path)
return session.query(Track).filter(and_(Track.filename == filename, Directory.path == directory, Track.file_index == track)).one()
+ @staticmethod
+ def search(session, *args, **kwargs):
+ r = session.query(Track)
+ for f, n in ((Artist, 'artist'), (Track, 'title'), (Album, 'album')):
+ if n in kwargs:
+ if f != Track:
+ r = r.join(f)
+ r = r.filter(f.name.ilike('%{0}%'.format(kwargs[n])))
+ return r.all()
+
def get_path(self):
return os.path.join(self.directory.path, self.filename)