Clean up album and artist views
This commit is contained in:
@ -90,6 +90,24 @@ class Album(TimeStampedModel):
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse("music:album_detail", kwargs={'slug': self.uuid})
|
||||
|
||||
def scrobbles(self):
|
||||
from scrobbles.models import Scrobble
|
||||
|
||||
return Scrobble.objects.filter(
|
||||
track__in=self.track_set.all()
|
||||
).order_by('-timestamp')
|
||||
|
||||
@property
|
||||
def tracks(self):
|
||||
return (
|
||||
self.track_set.all()
|
||||
.annotate(scrobble_count=models.Count('scrobble'))
|
||||
.order_by('-scrobble_count')
|
||||
)
|
||||
|
||||
@property
|
||||
def primary_artist(self):
|
||||
return self.artists.first()
|
||||
|
||||
@ -6,6 +6,11 @@ app_name = 'music'
|
||||
|
||||
urlpatterns = [
|
||||
path('albums/', views.AlbumListView.as_view(), name='albums_list'),
|
||||
path(
|
||||
'album/<slug:slug>/',
|
||||
views.AlbumDetailView.as_view(),
|
||||
name='album_detail',
|
||||
),
|
||||
path("tracks/", views.TrackListView.as_view(), name='tracks_list'),
|
||||
path(
|
||||
'tracks/<slug:slug>/',
|
||||
|
||||
@ -49,3 +49,15 @@ class ArtistDetailView(generic.DetailView):
|
||||
|
||||
class AlbumListView(generic.ListView):
|
||||
model = Album
|
||||
|
||||
|
||||
class AlbumDetailView(generic.DetailView):
|
||||
model = Album
|
||||
slug_field = 'uuid'
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context_data = super().get_context_data(**kwargs)
|
||||
# context_data['charts'] = ChartRecord.objects.filter(
|
||||
# track__album=self.object, rank__in=[1, 2, 3]
|
||||
# )
|
||||
return context_data
|
||||
|
||||
@ -23,11 +23,12 @@ def lookup_artist_from_tadb(name: str) -> dict:
|
||||
return {}
|
||||
|
||||
results = json.loads(response.content)
|
||||
artist = results['artists'][0]
|
||||
if results['artists']:
|
||||
artist = results['artists'][0]
|
||||
|
||||
artist_info['biography'] = artist['strBiographyEN']
|
||||
artist_info['genre'] = artist['strGenre']
|
||||
artist_info['mood'] = artist['strMood']
|
||||
artist_info['thumb_url'] = artist['strArtistThumb']
|
||||
artist_info['biography'] = artist['strBiographyEN']
|
||||
artist_info['genre'] = artist['strGenre']
|
||||
artist_info['mood'] = artist['strMood']
|
||||
artist_info['thumb_url'] = artist['strArtistThumb']
|
||||
|
||||
return artist_info
|
||||
|
||||
Reference in New Issue
Block a user