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.

65 lines
2.1 KiB

  1. from django.db import models
  2. class Artist(models.Model):
  3. class Meta:
  4. verbose_name = "Artist"
  5. verbose_name_plural = "Artists"
  6. artist_id = models.CharField(primary_key=True, max_length=30)
  7. # unique since only storing one genre per artist right now
  8. name = models.CharField(unique=True, max_length=50)
  9. genre = models.CharField(max_length=20)
  10. def __str__(self):
  11. return self.name
  12. class User(models.Model):
  13. class Meta:
  14. verbose_name = "User"
  15. verbose_name_plural = "Users"
  16. user_id = models.CharField(primary_key=True, max_length=30) # the user's Spotify ID
  17. user_name = models.CharField(max_length=30, blank=True) # User's Spotify user name, if set
  18. def __str__(self):
  19. return self.user_name
  20. class Track(models.Model):
  21. class Meta:
  22. verbose_name = "Track"
  23. verbose_name_plural = "Tracks"
  24. track_id = models.CharField(max_length=30)
  25. artists = models.ManyToManyField(Artist)
  26. year = models.PositiveSmallIntegerField()
  27. popularity = models.DecimalField(decimal_places=2, max_digits=2)
  28. runtime = models.PositiveSmallIntegerField()
  29. name = models.CharField(max_length=75)
  30. users = models.ManyToManyField(User)
  31. def __str__(self):
  32. return self.name
  33. class AudioFeatures(models.Model):
  34. class Meta:
  35. verbose_name = "AudioFeatures"
  36. verbose_name_plural = "AudioFeatures"
  37. track = models.OneToOneField(Track, on_delete=models.CASCADE, primary_key=True,)
  38. danceability = models.DecimalField(decimal_places=2, max_digits=2)
  39. energy = models.DecimalField(decimal_places=2, max_digits=2)
  40. loudness = models.DecimalField(decimal_places=2, max_digits=2)
  41. speechiness = models.DecimalField(decimal_places=2, max_digits=2)
  42. acousticness = models.DecimalField(decimal_places=2, max_digits=2)
  43. instrumentalness = models.DecimalField(decimal_places=2, max_digits=2)
  44. valence = models.DecimalField(decimal_places=2, max_digits=2)
  45. tempo = models.DecimalField(decimal_places=2, max_digits=2)
  46. def __str__(self):
  47. return super(AudioFeatures, self).__str__()