I have a database structure for playlists and tracks.
My database code looks like this:
#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')
)
I have created a controller that retrieves all tracks in a specific playlist by accessing these tables. Here's what that code looks like:
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)
)
For some reason, this code does not return what I expect, which is a list of the tracks from that playlist.
What could be the problem?
Thank you