def get_context_data(self, **kwargs): artist = self.get_object() relevant_contributions = EntityContribution.objects.filter( song=OuterRef('pk'), artist=artist) songs = filter_visible_to_user( Song.objects.all(), self.request.user).annotate( relevant=Exists(relevant_contributions)).filter( relevant=True).annotate(num_notes=Count('songnote')) context = super().get_context_data(**kwargs) context['songs'] = songs context['artist'] = artist context['notes'] = ArtistNote.items_visible_to( self.request.user).filter(artist=self.object) return context
def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['article'] = (Article.items_visible_to(self.request.user) .order_by('-pub_date').first()) context['events'] = get_events_for(self.request.user) context['posts'] = (Post.items_visible_to(self.request.user) .order_by('-pub_date')[:SiteIndex.POST_COUNT]) context['songs'] = (Song.items_visible_to(self.request.user) .order_by('-pub_date')[:SiteIndex.SONG_COUNT]) context['song_of_the_day'] = self.get_song_of_the_day() context['annotation'] = (SongNote.items_visible_to(self.request.user) .order_by('-pub_date').first()) song_notes = SongNote.items_visible_to(self.request.user).order_by( '-pub_date')[:SiteIndex.ANNOTATION_COUNT] artist_notes = ArtistNote.items_visible_to(self.request.user).order_by( '-pub_date')[:SiteIndex.ANNOTATION_COUNT] notes = (list(song_notes) + list(artist_notes)) notes.sort(key=lambda x: x.pub_date, reverse=True) context['annotations'] = notes[:SiteIndex.ANNOTATION_COUNT] return context