Сделал Плейлист и добавил рекомендацию на главную страницу
This commit is contained in:
@@ -79,3 +79,40 @@ class Track(BaseModel):
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.album.artist} - {self.title}"
|
||||
|
||||
|
||||
class Playlist(BaseModel):
|
||||
name = models.CharField(max_length=200)
|
||||
tracks = models.ManyToManyField(Track, related_name="playlists")
|
||||
|
||||
def __str__(self):
|
||||
return f"Playlist: {self.name}"
|
||||
|
||||
|
||||
class RecommendationPlaylist(BaseModel):
|
||||
class Meta:
|
||||
constraints = [
|
||||
models.UniqueConstraint(
|
||||
fields=["is_actual"],
|
||||
condition=models.Q(is_actual=True),
|
||||
name="unique_actual_recommendation_playlist",
|
||||
)
|
||||
]
|
||||
|
||||
name = models.CharField(max_length=200)
|
||||
description = models.TextField(blank=True)
|
||||
playlist = models.ForeignKey(
|
||||
Playlist, on_delete=models.CASCADE, related_name="recommendations"
|
||||
)
|
||||
is_actual = models.BooleanField(default=False)
|
||||
|
||||
def __str__(self):
|
||||
return f"Recommendation Playlist: {self.name}"
|
||||
|
||||
def switch_actual(self):
|
||||
if not self.is_actual:
|
||||
(RecommendationPlaylist.objects
|
||||
.filter(is_actual=True)
|
||||
.update(is_actual=False))
|
||||
self.is_actual = True
|
||||
self.save()
|
||||
|
||||
Reference in New Issue
Block a user