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.

103 lines
2.9 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. name = models.CharField(max_length=50)
  21. genres = models.ManyToManyField(Genre, blank=True)
  22. def __str__(self):
  23. return self.name
  24. # }}} Artist #
  25. # User {{{ #
  26. class User(models.Model):
  27. class Meta:
  28. verbose_name = "User"
  29. verbose_name_plural = "Users"
  30. user_id = models.CharField(primary_key=True, max_length=MAX_ID) # the user's Spotify ID
  31. user_secret = models.CharField(max_length=50, default='')
  32. def __str__(self):
  33. return self.user_id
  34. # }}} User #
  35. # Track {{{ #
  36. class Track(models.Model):
  37. class Meta:
  38. verbose_name = "Track"
  39. verbose_name_plural = "Tracks"
  40. track_id = models.CharField(primary_key=True, max_length=MAX_ID)
  41. # artist = models.ForeignKey(Artist, on_delete=models.CASCADE)
  42. artists = models.ManyToManyField(Artist, blank=True)
  43. year = models.PositiveSmallIntegerField()
  44. popularity = models.PositiveSmallIntegerField()
  45. runtime = models.PositiveSmallIntegerField()
  46. name = models.CharField(max_length=200)
  47. users = models.ManyToManyField(User, blank=True)
  48. genre = models.ForeignKey(Genre, on_delete=models.CASCADE, blank=True,
  49. null=True)
  50. def __str__(self):
  51. track_str = "{}, genre: {}, artists: [".format(self.name, self.genre)
  52. for artist in self.artists.all():
  53. track_str += "{}, ".format(artist.name)
  54. track_str += "]"
  55. return track_str
  56. # }}} Track #
  57. # AudioFeatures {{{ #
  58. class AudioFeatures(models.Model):
  59. class Meta:
  60. verbose_name = "AudioFeatures"
  61. verbose_name_plural = "AudioFeatures"
  62. track = models.OneToOneField(Track, on_delete=models.CASCADE, primary_key=True,)
  63. acousticness = models.DecimalField(decimal_places=3, max_digits=3)
  64. danceability = models.DecimalField(decimal_places=3, max_digits=3)
  65. energy = models.DecimalField(decimal_places=3, max_digits=3)
  66. instrumentalness = models.DecimalField(decimal_places=3, max_digits=3)
  67. loudness = models.DecimalField(decimal_places=3, max_digits=6)
  68. speechiness = models.DecimalField(decimal_places=3, max_digits=3)
  69. tempo = models.DecimalField(decimal_places=3, max_digits=6)
  70. valence = models.DecimalField(decimal_places=3, max_digits=3)
  71. def __str__(self):
  72. return super(AudioFeatures, self).__str__()
  73. # }}} AudioFeatures #