Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #table for tracks
- db.define_table('track',
- Field('artist'),
- Field('album'),
- Field('title'),
- Field('duration', 'float'),
- ......
- )
- #table for playlists
- db.define_table('playlist',
- Field('title')
- )
- #table for references
- db.define_table('playlist_reference',
- Field('playlist', 'reference playlist'),
- Field('track','reference track')
- )
- def get_playlist_tracks():
- title = request.vars.title
- tracks = []
- q = (title == db.playlist.title)
- #searches the playlist database for the playlist that
- #matches the title of the playlist whose tracks I want to retrieve
- #and gives me its id
- plist_id = db(q).select().first().id
- #returns all the references in which that playlist appears
- q = (plist_id == db.playlist_reference.playlist)
- refs = db(q).select(db.playlist_reference.ALL)
- #for each reference I get the track id and append to tracks array
- for i, r in enumerate(refs):
- t_id = r.track
- q = (t_id == db.track.id)
- track = db(q).select(db.track.ALL)
- print track
- tracks.append(track)
- return response.json(dict(
- tracks=tracks)
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement