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.

101 lines
2.8 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. # Genre {{{ #
  5. class Genre(models.Model):
  6. class Meta:
  7. verbose_name = "Genre"
  8. verbose_name_plural = "Genres"
  9. name = models.CharField(primary_key=True, max_length=50)
  10. num_songs = models.PositiveIntegerField()
  11. def __str__(self):
  12. return self.name
  13. # }}} Genre #
  14. # Artist {{{ #
  15. class Artist(models.Model):
  16. class Meta:
  17. verbose_name = "Artist"
  18. verbose_name_plural = "Artists"
  19. artist_id = models.CharField(primary_key=True, max_length=MAX_ID)
  20. # unique since only storing one genre per artist right now
  21. name = models.CharField(unique=True, max_length=50)
  22. genres = models.ManyToManyField(Genre, blank=True)
  23. def __str__(self):
  24. return self.name
  25. # }}} Artist #
  26. # User {{{ #
  27. class User(models.Model):
  28. class Meta:
  29. verbose_name = "User"
  30. verbose_name_plural = "Users"
  31. user_id = models.CharField(primary_key=True, max_length=MAX_ID) # the user's Spotify ID
  32. user_secret = models.CharField(max_length=30, default='')
  33. def __str__(self):
  34. return self.user_id
  35. # }}} User #
  36. # Track {{{ #
  37. class Track(models.Model):
  38. class Meta:
  39. verbose_name = "Track"
  40. verbose_name_plural = "Tracks"
  41. track_id = models.CharField(primary_key=True, max_length=MAX_ID)
  42. # artist = models.ForeignKey(Artist, on_delete=models.CASCADE)
  43. artists = models.ManyToManyField(Artist, blank=True)
  44. year = models.PositiveSmallIntegerField()
  45. popularity = models.PositiveSmallIntegerField()
  46. runtime = models.PositiveSmallIntegerField()
  47. name = models.CharField(max_length=200)
  48. users = models.ManyToManyField(User, blank=True)
  49. # genre = models.CharField(max_length=30)
  50. genre = models.ForeignKey(Genre, on_delete=models.CASCADE, blank=True,
  51. null=True)
  52. def __str__(self):
  53. return self.name
  54. # }}} Track #
  55. # AudioFeatures {{{ #
  56. class AudioFeatures(models.Model):
  57. class Meta:
  58. verbose_name = "AudioFeatures"
  59. verbose_name_plural = "AudioFeatures"
  60. track = models.OneToOneField(Track, on_delete=models.CASCADE, primary_key=True,)
  61. acousticness = models.DecimalField(decimal_places=3, max_digits=3)
  62. danceability = models.DecimalField(decimal_places=3, max_digits=3)
  63. energy = models.DecimalField(decimal_places=3, max_digits=3)
  64. instrumentalness = models.DecimalField(decimal_places=3, max_digits=3)
  65. loudness = models.DecimalField(decimal_places=3, max_digits=6)
  66. speechiness = models.DecimalField(decimal_places=3, max_digits=3)
  67. tempo = models.DecimalField(decimal_places=3, max_digits=6)
  68. valence = models.DecimalField(decimal_places=3, max_digits=3)
  69. def __str__(self):
  70. return super(AudioFeatures, self).__str__()
  71. # }}} AudioFeatures #