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.

69 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)
  17. username = models.CharField(max_length=30)
  18. def __str__(self):
  19. return self.username
  20. class Track(models.Model):
  21. class Meta:
  22. verbose_name = "Track"
  23. verbose_name_plural = "Tracks"
  24. unique_together = ('track_id', 'artist',)
  25. track_id = models.CharField(max_length=30)
  26. artist = models.ForeignKey(Artist, on_delete=models.CASCADE)
  27. year = models.PositiveSmallIntegerField()
  28. popularity = models.DecimalField(decimal_places=2, max_digits=2)
  29. runtime = models.PositiveSmallIntegerField()
  30. name = models.CharField(max_length=75)
  31. users = models.ManyToManyField(User)
  32. def __str__(self):
  33. return self.name
  34. class AudioFeatures(models.Model):
  35. class Meta:
  36. verbose_name = "AudioFeatures"
  37. verbose_name_plural = "AudioFeatures"
  38. track = models.OneToOneField(Track, on_delete=models.CASCADE, primary_key=True,)
  39. danceability = models.DecimalField(decimal_places=2, max_digits=2)
  40. energy = models.DecimalField(decimal_places=2, max_digits=2)
  41. loudness = models.DecimalField(decimal_places=2, max_digits=2)
  42. speechiness = models.DecimalField(decimal_places=2, max_digits=2)
  43. acousticness = models.DecimalField(decimal_places=2, max_digits=2)
  44. instrumentalness = models.DecimalField(decimal_places=2, max_digits=2)
  45. valence = models.DecimalField(decimal_places=2, max_digits=2)
  46. tempo = models.DecimalField(decimal_places=2, max_digits=2)
  47. def __str__(self):
  48. return super(AudioFeatures, self).__str__()