mirror of
https://code.eliotberriot.com/funkwhale/funkwhale.git
synced 2025-10-06 04:59:55 +02:00
Initial commit that merge both the front end and the API in the same repository
This commit is contained in:
commit
76f98b74dd
285 changed files with 51318 additions and 0 deletions
33
api/funkwhale_api/playlists/models.py
Normal file
33
api/funkwhale_api/playlists/models.py
Normal file
|
@ -0,0 +1,33 @@
|
|||
from django.db import models
|
||||
from django.utils import timezone
|
||||
|
||||
from mptt.models import MPTTModel, TreeOneToOneField
|
||||
|
||||
|
||||
class Playlist(models.Model):
|
||||
name = models.CharField(max_length=50)
|
||||
is_public = models.BooleanField(default=False)
|
||||
user = models.ForeignKey('users.User', related_name="playlists")
|
||||
creation_date = models.DateTimeField(default=timezone.now)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
def add_track(self, track, previous=None):
|
||||
plt = PlaylistTrack(previous=previous, track=track, playlist=self)
|
||||
plt.save()
|
||||
|
||||
return plt
|
||||
|
||||
|
||||
class PlaylistTrack(MPTTModel):
|
||||
track = models.ForeignKey('music.Track', related_name='playlist_tracks')
|
||||
previous = TreeOneToOneField('self', blank=True, null=True, related_name='next')
|
||||
playlist = models.ForeignKey(Playlist, related_name='playlist_tracks')
|
||||
|
||||
class MPTTMeta:
|
||||
level_attr = 'position'
|
||||
parent_attr = 'previous'
|
||||
|
||||
class Meta:
|
||||
ordering = ('-playlist', 'position')
|
Loading…
Add table
Add a link
Reference in a new issue