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.

104 lines
3.0 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=50, 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.ForeignKey(Genre, on_delete=models.CASCADE, blank=True,
  50. null=True)
  51. def __str__(self):
  52. track_str = "{}, genre: {}, artists: [".format(self.name, self.genre)
  53. for artist in self.artists.all():
  54. track_str += "{}, ".format(artist.name)
  55. track_str += "]"
  56. return track_str
  57. # }}} Track #
  58. # AudioFeatures {{{ #
  59. class AudioFeatures(models.Model):
  60. class Meta:
  61. verbose_name = "AudioFeatures"
  62. verbose_name_plural = "AudioFeatures"
  63. track = models.OneToOneField(Track, on_delete=models.CASCADE, primary_key=True,)
  64. acousticness = models.DecimalField(decimal_places=3, max_digits=3)
  65. danceability = models.DecimalField(decimal_places=3, max_digits=3)
  66. energy = models.DecimalField(decimal_places=3, max_digits=3)
  67. instrumentalness = models.DecimalField(decimal_places=3, max_digits=3)
  68. loudness = models.DecimalField(decimal_places=3, max_digits=6)
  69. speechiness = models.DecimalField(decimal_places=3, max_digits=3)
  70. tempo = models.DecimalField(decimal_places=3, max_digits=6)
  71. valence = models.DecimalField(decimal_places=3, max_digits=3)
  72. def __str__(self):
  73. return super(AudioFeatures, self).__str__()
  74. # }}} AudioFeatures #