Graphs and tables for your Spotify account.

82 lines
2.5 KiB

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