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
|
|
|
|
|
2021-07-09 18:25:07 +00:00
|
|
|
|
2020-12-16 17:36:29 +00:00
|
|
|
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']
|
2021-07-09 18:25:07 +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
|
2021-07-09 18:25:07 +00:00
|
|
|
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]
|
2021-07-09 18:25:07 +00:00
|
|
|
credit_songs = artist.written_songs.all(
|
|
|
|
) | artist.composed_songs.all() | artist.arranged_songs.all()
|
2020-12-17 07:12:26 +00:00
|
|
|
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:
|
2021-07-09 18:25:07 +00:00
|
|
|
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)
|
2020-12-17 07:12:26 +00:00
|
|
|
credit_songs = credit_songs.distinct()
|
|
|
|
outside_songs = outside_songs.distinct()
|
2021-07-09 18:25:07 +00:00
|
|
|
return render(request, 'artists/show.html', {'artist': artist, 'credit_songs': credit_songs, 'outside_songs': outside_songs})
|