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.

78 lines
2.3 KiB

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