Advertisement
Guest User

Untitled

a guest
Dec 6th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. #table for tracks
  2. db.define_table('track',
  3. Field('artist'),
  4. Field('album'),
  5. Field('title'),
  6. Field('duration', 'float'),
  7. ......
  8. )
  9. #table for playlists
  10. db.define_table('playlist',
  11. Field('title')
  12. )
  13. #table for references
  14. db.define_table('playlist_reference',
  15. Field('playlist', 'reference playlist'),
  16. Field('track','reference track')
  17. )
  18.  
  19. def get_playlist_tracks():
  20. title = request.vars.title
  21. tracks = []
  22.  
  23. q = (title == db.playlist.title)
  24.  
  25. #searches the playlist database for the playlist that
  26. #matches the title of the playlist whose tracks I want to retrieve
  27. #and gives me its id
  28. plist_id = db(q).select().first().id
  29.  
  30. #returns all the references in which that playlist appears
  31. q = (plist_id == db.playlist_reference.playlist)
  32. refs = db(q).select(db.playlist_reference.ALL)
  33.  
  34. #for each reference I get the track id and append to tracks array
  35. for i, r in enumerate(refs):
  36. t_id = r.track
  37. q = (t_id == db.track.id)
  38. track = db(q).select(db.track.ALL)
  39. print track
  40. tracks.append(track)
  41.  
  42. return response.json(dict(
  43. tracks=tracks)
  44. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement