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
21
api/funkwhale_api/history/models.py
Normal file
21
api/funkwhale_api/history/models.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
from django.utils import timezone
|
||||
from django.db import models
|
||||
from django.core.exceptions import ValidationError
|
||||
|
||||
from funkwhale_api.music.models import Track
|
||||
|
||||
|
||||
class Listening(models.Model):
|
||||
end_date = models.DateTimeField(default=timezone.now, null=True, blank=True)
|
||||
track = models.ForeignKey(Track, related_name="listenings")
|
||||
user = models.ForeignKey('users.User', related_name="listenings", null=True, blank=True)
|
||||
session_key = models.CharField(max_length=100, null=True, blank=True)
|
||||
|
||||
class Meta:
|
||||
ordering = ('-end_date',)
|
||||
|
||||
def save(self, **kwargs):
|
||||
if not self.user and not self.session_key:
|
||||
raise ValidationError('Cannot have both session_key and user empty for listening')
|
||||
|
||||
super().save(**kwargs)
|
||||
Loading…
Add table
Add a link
Reference in a new issue