Explorar o código

Add scrobble count property to tracks

Colin Powell %!s(int64=2) %!d(string=hai) anos
pai
achega
e4027402ed
Modificáronse 1 ficheiros con 6 adicións e 0 borrados
  1. 6 0
      vrobbler/apps/music/models.py

+ 6 - 0
vrobbler/apps/music/models.py

@@ -2,6 +2,8 @@ import logging
 from typing import Dict, Optional
 from uuid import uuid4
 
+from django.apps.config import cached_property
+
 from django.db import models
 from django.utils.translation import gettext_lazy as _
 from django_extensions.db.models import TimeStampedModel
@@ -55,6 +57,10 @@ class Track(TimeStampedModel):
     def mb_link(self):
         return f"https://musicbrainz.org/recording/{self.musicbrainz_id}"
 
+    @cached_property
+    def scrobble_count(self):
+        return self.scrobble_set.filter(in_progress=False).count()
+
     @classmethod
     def find_or_create(
         cls, artist_dict: Dict, album_dict: Dict, track_dict: Dict