From e4027402eda6900250af46343fd491305a3fe97c Mon Sep 17 00:00:00 2001 From: Colin Powell Date: Sun, 8 Jan 2023 19:44:07 -0500 Subject: [PATCH] Add scrobble count property to tracks --- vrobbler/apps/music/models.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/vrobbler/apps/music/models.py b/vrobbler/apps/music/models.py index 1481f72..94fdcb4 100644 --- a/vrobbler/apps/music/models.py +++ b/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