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
18
api/funkwhale_api/favorites/models.py
Normal file
18
api/funkwhale_api/favorites/models.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
from django.db import models
|
||||
from django.utils import timezone
|
||||
|
||||
from funkwhale_api.music.models import Track
|
||||
|
||||
class TrackFavorite(models.Model):
|
||||
creation_date = models.DateTimeField(default=timezone.now)
|
||||
user = models.ForeignKey('users.User', related_name='track_favorites')
|
||||
track = models.ForeignKey(Track, related_name='track_favorites')
|
||||
|
||||
class Meta:
|
||||
unique_together = ('track', 'user')
|
||||
ordering = ('-creation_date',)
|
||||
|
||||
@classmethod
|
||||
def add(cls, track, user):
|
||||
favorite, created = cls.objects.get_or_create(user=user, track=track)
|
||||
return favorite
|
||||
Loading…
Add table
Add a link
Reference in a new issue