diff options
Diffstat (limited to 'db.py')
-rw-r--r-- | db.py | 12 |
1 files changed, 11 insertions, 1 deletions
@@ -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) |