models.py 748 Bytes
Newer Older
1
2
3
4
5
6
7
from django.utils import timezone
from django.db import models

from funkwhale_api.music.models import Track


class Listening(models.Model):
Eliot Berriot's avatar
Eliot Berriot committed
8
    creation_date = models.DateTimeField(default=timezone.now, null=True, blank=True)
Eliot Berriot's avatar
Eliot Berriot committed
9
    track = models.ForeignKey(
Eliot Berriot's avatar
Eliot Berriot committed
10
11
        Track, related_name="listenings", on_delete=models.CASCADE
    )
Eliot Berriot's avatar
Eliot Berriot committed
12
    user = models.ForeignKey(
Eliot Berriot's avatar
Eliot Berriot committed
13
        "users.User",
Eliot Berriot's avatar
Eliot Berriot committed
14
15
16
        related_name="listenings",
        null=True,
        blank=True,
Eliot Berriot's avatar
Eliot Berriot committed
17
18
        on_delete=models.CASCADE,
    )
19
20
21
    session_key = models.CharField(max_length=100, null=True, blank=True)

    class Meta:
Eliot Berriot's avatar
Eliot Berriot committed
22
        ordering = ("-creation_date",)
23

24
    def get_activity_url(self):
Eliot Berriot's avatar
Eliot Berriot committed
25
        return "{}/listenings/tracks/{}".format(self.user.get_activity_url(), self.pk)