aad9343569
Moves from_json to utils and splits the models to files in a module
33 lines
1.0 KiB
Python
33 lines
1.0 KiB
Python
from django.db import models
|
|
from .album import Album
|
|
from .artist import Artist
|
|
from .utils import from_json
|
|
|
|
class TrackManager(models.Manager):
|
|
def get_queryset(self):
|
|
return super().get_queryset().filter(old=False)
|
|
|
|
class Track(models.Model):
|
|
def __str__(self):
|
|
s = f"'{self.name}'"
|
|
if self.artists.count() > 0:
|
|
artists = list(map(lambda a:a.name, self.artists.all()))
|
|
s += " by "
|
|
s += " & ".join(artists)
|
|
return s
|
|
id = models.CharField(primary_key=True, max_length=128)
|
|
name = models.CharField(max_length=255)
|
|
artists = models.ManyToManyField(Artist)
|
|
album = models.ForeignKey(Album, null=True, on_delete=models.SET_NULL)
|
|
|
|
explicit = models.BooleanField(default=False)
|
|
duration_ms = models.PositiveIntegerField(null=True)
|
|
popularity = models.PositiveIntegerField(null=True)
|
|
|
|
banter = models.TextField(blank=True)
|
|
|
|
old = models.BooleanField(default=False)
|
|
|
|
objects = TrackManager()
|
|
all_tracks = models.Manager()
|