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.

88 lines
2.6 KiB

  1. from django.db import models
  2. from login.models import User
  3. # id's are 22 in length in examples but set to 30 for buffer
  4. MAX_ID = 30
  5. # Genre {{{ #
  6. class Genre(models.Model):
  7. class Meta:
  8. verbose_name = "Genre"
  9. verbose_name_plural = "Genres"
  10. name = models.CharField(primary_key=True, max_length=50)
  11. num_songs = models.PositiveIntegerField()
  12. def __str__(self):
  13. return self.name
  14. # }}} Genre #
  15. # Artist {{{ #
  16. class Artist(models.Model):
  17. class Meta:
  18. verbose_name = "Artist"
  19. verbose_name_plural = "Artists"
  20. id = models.CharField(primary_key=True, max_length=MAX_ID)
  21. name = models.CharField(max_length=50)
  22. genres = models.ManyToManyField(Genre, blank=True)
  23. def __str__(self):
  24. return self.name
  25. # }}} Artist #
  26. # Track {{{ #
  27. class Track(models.Model):
  28. class Meta:
  29. verbose_name = "Track"
  30. verbose_name_plural = "Tracks"
  31. id = models.CharField(primary_key=True, max_length=MAX_ID)
  32. # artist = models.ForeignKey(Artist, on_delete=models.CASCADE)
  33. artists = models.ManyToManyField(Artist, blank=True)
  34. year = models.PositiveSmallIntegerField()
  35. popularity = models.PositiveSmallIntegerField()
  36. runtime = models.PositiveSmallIntegerField()
  37. name = models.CharField(max_length=200)
  38. users = models.ManyToManyField(User, blank=True)
  39. genre = models.ForeignKey(Genre, on_delete=models.CASCADE, blank=True,
  40. null=True)
  41. def __str__(self):
  42. track_str = "{}, genre: {}, artists: [".format(self.name, self.genre)
  43. for artist in self.artists.all():
  44. track_str += "{}, ".format(artist.name)
  45. track_str += "]"
  46. return track_str
  47. # }}} Track #
  48. # AudioFeatures {{{ #
  49. class AudioFeatures(models.Model):
  50. class Meta:
  51. verbose_name = "AudioFeatures"
  52. verbose_name_plural = "AudioFeatures"
  53. track = models.OneToOneField(Track, on_delete=models.CASCADE, primary_key=True,)
  54. acousticness = models.DecimalField(decimal_places=3, max_digits=3)
  55. danceability = models.DecimalField(decimal_places=3, max_digits=3)
  56. energy = models.DecimalField(decimal_places=3, max_digits=3)
  57. instrumentalness = models.DecimalField(decimal_places=3, max_digits=3)
  58. loudness = models.DecimalField(decimal_places=3, max_digits=6)
  59. speechiness = models.DecimalField(decimal_places=3, max_digits=3)
  60. tempo = models.DecimalField(decimal_places=3, max_digits=6)
  61. valence = models.DecimalField(decimal_places=3, max_digits=3)
  62. def __str__(self):
  63. return super(AudioFeatures, self).__str__()
  64. # }}} AudioFeatures #