1
0
mirror of https://github.com/Damillora/Altessimo synced 2024-11-24 06:37:33 +00:00
Altessimo/artists/views.py

27 lines
1.2 KiB
Python
Raw Normal View History

2020-12-15 21:32:20 +00:00
from django.shortcuts import render
# Create your views here.
2020-12-16 17:36:29 +00:00
from .models import Artist
from songs.models import OutsideSong
def artist_index(request):
artists = Artist.objects.all()
2020-12-17 15:48:07 +00:00
objs = {}
if "q" in request.GET:
q = request.GET['q']
2020-12-17 15:59:22 +00:00
artists = Artist.objects.filter(name__icontains=q) | Artist.objects.filter(romanized_name__icontains=q)
2020-12-17 15:48:07 +00:00
objs['q'] = q
objs['artists'] = artists
return render(request,'artists/index.html',objs)
2020-12-16 17:36:29 +00:00
def artist_show(request, slug):
artist = Artist.objects.filter(slug=slug)[0]
2020-12-17 07:12:26 +00:00
credit_songs = artist.written_songs.all() | artist.composed_songs.all() | artist.arranged_songs.all()
aliases = artist.aliases.all()
2020-12-16 17:36:29 +00:00
outside_songs = OutsideSong.objects.filter(composer=artist)
2020-12-17 07:12:26 +00:00
for alias in aliases:
credit_songs = credit_songs | alias.written_songs.all() | artist.composed_songs.all() | artist.arranged_songs.all()
outside_songs = outside_songs | OutsideSong.objects.filter(composer=alias)
credit_songs = credit_songs.distinct()
outside_songs = outside_songs.distinct()
2020-12-16 17:36:29 +00:00
return render(request,'artists/show.html',{'artist': artist,'credit_songs':credit_songs,'outside_songs':outside_songs})