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. genre = models.CharField(max_length=30)
  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=MAX_ID) # 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. track_id = models.CharField(primary_key=True, max_length=MAX_ID)
  32. # artist = models.ForeignKey(Artist, on_delete=models.CASCADE)
  33. artists = models.ManyToManyField(Artist, blank=True)
  34. year = models.PositiveSmallIntegerField()
  35. popularity = models.PositiveSmallIntegerField()
  36. runtime = models.PositiveSmallIntegerField()
  37. name = models.CharField(max_length=150)
  38. users = models.ManyToManyField(User, blank=True)
  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 #