Graphs and tables for your Spotify account.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
2.6 KiB

  1. from django.db import models
  2. # id's are 22 in length in examples but set to 30 for buffer
  3. MAX_ID = 30
  4. # Artist {{{ #
  5. class Artist(models.Model):
  6. class Meta:
  7. verbose_name = "Artist"
  8. verbose_name_plural = "Artists"
  9. artist_id = models.CharField(primary_key=True, max_length=MAX_ID)
  10. # unique since only storing one genre per artist right now
  11. name = models.CharField(unique=True, max_length=50)
  12. def __str__(self):
  13. return self.name
  14. # }}} Artist #
  15. # User {{{ #
  16. class User(models.Model):
  17. class Meta:
  18. verbose_name = "User"
  19. verbose_name_plural = "Users"
  20. user_id = models.CharField(primary_key=True, max_length=MAX_ID) # the user's Spotify ID
  21. user_secret = models.CharField(max_length=30, default='')
  22. def __str__(self):
  23. return self.user_id
  24. # }}} User #
  25. # Track {{{ #
  26. class Track(models.Model):
  27. class Meta:
  28. verbose_name = "Track"
  29. verbose_name_plural = "Tracks"
  30. track_id = models.CharField(primary_key=True, max_length=MAX_ID)
  31. # artist = models.ForeignKey(Artist, on_delete=models.CASCADE)
  32. artists = models.ManyToManyField(Artist, blank=True)
  33. year = models.PositiveSmallIntegerField()
  34. popularity = models.PositiveSmallIntegerField()
  35. runtime = models.PositiveSmallIntegerField()
  36. name = models.CharField(max_length=150)
  37. users = models.ManyToManyField(User, blank=True)
  38. genre = models.CharField(max_length=30, default="")
  39. def __str__(self):
  40. track_str = "{}, genre: {}, artists: [".format(self.name, self.genre)
  41. for artist in self.artists.all():
  42. track_str += "{}, ".format(artist.name)
  43. track_str += "]"
  44. return track_str
  45. # }}} Track #
  46. # AudioFeatures {{{ #
  47. class AudioFeatures(models.Model):
  48. class Meta:
  49. verbose_name = "AudioFeatures"
  50. verbose_name_plural = "AudioFeatures"
  51. track = models.OneToOneField(Track, on_delete=models.CASCADE, primary_key=True,)
  52. acousticness = models.DecimalField(decimal_places=3, max_digits=3)
  53. danceability = models.DecimalField(decimal_places=3, max_digits=3)
  54. energy = models.DecimalField(decimal_places=3, max_digits=3)
  55. instrumentalness = models.DecimalField(decimal_places=3, max_digits=3)
  56. loudness = models.DecimalField(decimal_places=3, max_digits=6)
  57. speechiness = models.DecimalField(decimal_places=3, max_digits=3)
  58. tempo = models.DecimalField(decimal_places=3, max_digits=6)
  59. valence = models.DecimalField(decimal_places=3, max_digits=3)
  60. def __str__(self):
  61. return super(AudioFeatures, self).__str__()
  62. # }}} AudioFeatures #