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.

83 lines
2.4 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=200)
  37. users = models.ManyToManyField(User, blank=True)
  38. genre = models.CharField(max_length=30)
  39. def __str__(self):
  40. return self.name
  41. # }}} Track #
  42. # AudioFeatures {{{ #
  43. class AudioFeatures(models.Model):
  44. class Meta:
  45. verbose_name = "AudioFeatures"
  46. verbose_name_plural = "AudioFeatures"
  47. track = models.OneToOneField(Track, on_delete=models.CASCADE, primary_key=True,)
  48. acousticness = models.DecimalField(decimal_places=3, max_digits=3)
  49. danceability = models.DecimalField(decimal_places=3, max_digits=3)
  50. energy = models.DecimalField(decimal_places=3, max_digits=3)
  51. instrumentalness = models.DecimalField(decimal_places=3, max_digits=3)
  52. loudness = models.DecimalField(decimal_places=3, max_digits=6)
  53. speechiness = models.DecimalField(decimal_places=3, max_digits=3)
  54. tempo = models.DecimalField(decimal_places=3, max_digits=6)
  55. valence = models.DecimalField(decimal_places=3, max_digits=3)
  56. def __str__(self):
  57. return super(AudioFeatures, self).__str__()
  58. # }}} AudioFeatures #