def top_albums(n): try: top = [t.album for t in AlbumStatistics.select(orderBy=DESC(AlbumStatistics.q.play_count))[:n]] if len(top) < n: top = top + [album for album in Album.select()[:n-len(top)] if album not in top] return top except SQLObjectNotFound: return []
def album_search(keylist): album=[] for keyword in keylist: #tmp= Track.select(AND(Album.q.name.contains(keyword),Album.q.id==Track.q.album)) tmp= Album.select(Album.q.name.contains(keyword)) album.extend(tmp) album=set(album) return album