Add idol listing

This commit is contained in:
Damillora 2021-07-10 01:25:07 +07:00
parent b48045956c
commit f02f7b826a
23 changed files with 343 additions and 11 deletions

View File

@ -39,6 +39,7 @@ INSTALLED_APPS = [
'django.contrib.staticfiles',
'categories',
'artists',
'idols',
'songs',
'home',
]

View File

@ -21,5 +21,6 @@ urlpatterns = [
path('taxonomy/', include('categories.urls')),
path('artists/', include('artists.urls')),
path('songs/', include('songs.urls')),
path('idols/', include('idols.urls')),
path('admin/', admin.site.urls),
]

View File

@ -0,0 +1,31 @@
# Generated by Django 3.2.5 on 2021-07-09 17:06
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('artists', '0004_auto_20201216_1633'),
]
operations = [
migrations.CreateModel(
name='VoiceActor',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(blank=True, max_length=255)),
('romanized_name', models.CharField(max_length=255)),
],
),
migrations.CreateModel(
name='Idol',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(blank=True, max_length=255)),
('romanized_name', models.CharField(max_length=255)),
('voice_actor', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='artists.voiceactor')),
],
),
]

View File

@ -0,0 +1,20 @@
# Generated by Django 3.2.5 on 2021-07-09 17:20
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('songs', '0006_alter_song_idols'),
('artists', '0005_idol_voiceactor'),
]
operations = [
migrations.DeleteModel(
name='Idol',
),
migrations.DeleteModel(
name='VoiceActor',
),
]

View File

@ -34,3 +34,4 @@ class Artist(models.Model):
def save(self, *args, **kwargs):
self.slug = slugify(self.romanized_name)
super().save(*args,**kwargs)

View File

@ -4,24 +4,30 @@ from django.shortcuts import render
from .models import Artist
from songs.models import OutsideSong
def artist_index(request):
artists = Artist.objects.all()
objs = {}
if "q" in request.GET:
q = request.GET['q']
artists = Artist.objects.filter(name__icontains=q) | Artist.objects.filter(romanized_name__icontains=q)
artists = Artist.objects.filter(
name__icontains=q) | Artist.objects.filter(romanized_name__icontains=q)
objs['q'] = q
objs['artists'] = artists
return render(request,'artists/index.html',objs)
return render(request, 'artists/index.html', objs)
def artist_show(request, slug):
artist = Artist.objects.filter(slug=slug)[0]
credit_songs = artist.written_songs.all() | artist.composed_songs.all() | artist.arranged_songs.all()
credit_songs = artist.written_songs.all(
) | artist.composed_songs.all() | artist.arranged_songs.all()
aliases = artist.aliases.all()
outside_songs = OutsideSong.objects.filter(composer=artist)
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 | 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()
return render(request,'artists/show.html',{'artist': artist,'credit_songs':credit_songs,'outside_songs':outside_songs})
return render(request, 'artists/show.html', {'artist': artist, 'credit_songs': credit_songs, 'outside_songs': outside_songs})

0
idols/__init__.py Normal file
View File

6
idols/admin.py Normal file
View File

@ -0,0 +1,6 @@
from idols.models import Idol
from django.contrib import admin
# Register your models here.
admin.site.register(Idol)

6
idols/apps.py Normal file
View File

@ -0,0 +1,6 @@
from django.apps import AppConfig
class IdolsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'idols'

View File

@ -0,0 +1,32 @@
# Generated by Django 3.2.5 on 2021-07-09 17:20
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='VoiceActor',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(blank=True, max_length=255)),
('romanized_name', models.CharField(max_length=255)),
],
),
migrations.CreateModel(
name='Idol',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(blank=True, max_length=255)),
('romanized_name', models.CharField(max_length=255)),
('voice_actor', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='idols.voiceactor')),
],
),
]

View File

@ -0,0 +1,27 @@
# Generated by Django 3.2.5 on 2021-07-09 17:33
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('idols', '0001_initial'),
]
operations = [
migrations.RemoveField(
model_name='idol',
name='voice_actor',
),
migrations.AddField(
model_name='idol',
name='romanized_voice_actor_name',
field=models.CharField(blank=True, max_length=255),
),
migrations.AddField(
model_name='idol',
name='voice_actor_name',
field=models.CharField(blank=True, max_length=255),
),
]

View File

@ -0,0 +1,24 @@
# Generated by Django 3.2.5 on 2021-07-09 18:03
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('categories', '0009_auto_20201216_1732'),
('idols', '0002_auto_20210709_1733'),
]
operations = [
migrations.DeleteModel(
name='VoiceActor',
),
migrations.AddField(
model_name='idol',
name='branch',
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.PROTECT, to='categories.branch'),
preserve_default=False,
),
]

View File

30
idols/models.py Normal file
View File

@ -0,0 +1,30 @@
from django.db import models
# Create your models here.
# Create your models here.
class IdolManager(models.Manager):
def comma_to_qs(self, idols_str):
final_ids = []
if idols_str:
for idol in idols_str.split(','):
obj, created = self.get_or_create(romanized_name=idol.strip())
final_ids.append(obj.id)
qs = self.get_queryset().filter(id__in=final_ids).distinct()
return qs
return self.none()
class Idol(models.Model):
branch = models.ForeignKey("categories.Branch", on_delete=models.PROTECT)
name = models.CharField(max_length=255, blank=True)
romanized_name = models.CharField(max_length=255)
voice_actor_name = models.CharField(max_length=255, blank=True)
romanized_voice_actor_name = models.CharField(max_length=255, blank=True)
objects = IdolManager()
def __str__(self):
return self.romanized_name+" (CV: "+self.romanized_voice_actor_name+")"

View File

@ -0,0 +1,27 @@
{% extends 'layouts/base.html' %}
{% block title %} Idols {% endblock %}
{% block content %}
<h1>Idols</h1>
<form action="{{ request.path }}" method="GET">
<div class="input-group mb-3">
<input type="text" class="form-control" placeholder="Search" aria-label="Search" aria-describedby="search-button" name="q">
<button class="btn btn-outline-secondary" type="submit" id="search-button">Search</button>
</div>
</form>
<table class="table">
<thead>
<th>Idol</th>
</thead>
<tbody>
{% for idol in idols %}
<tr>
<td>
<a href="/idols/{{ idol.slug }}">{{ idol.romanized_name }}</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}

View File

@ -0,0 +1,32 @@
{% extends 'layouts/base.html' %}
{% block title %} Idol: {{ idol.romanized_name }} {% endblock %}
{% block content %}
<h1>Idol: {{ idol.romanized_name }}</h1>
<h2>Metadata</h2>
<table class="table">
<tbody>
{% if idol.name %}
<tr>
<th scope="row">
Name
</th>
<td>
{{ idol.name }}
</td>
</tr>
{% endif %}
{% if idol.romanized_name %}
<tr>
<th scope="row">
Romanized Name
</th>
<td>
{{ idol.romanized_name }}
</td>
</tr>
{% endif %}
</tbody>
</table>
{% endblock %}

3
idols/tests.py Normal file
View File

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

8
idols/urls.py Normal file
View File

@ -0,0 +1,8 @@
from django.urls import path
from . import views
urlpatterns = [
path('',views.idol_index),
path('<int:id>',views.idol_show)
]

19
idols/views.py Normal file
View File

@ -0,0 +1,19 @@
from idols.models import Idol
from django.shortcuts import render
# Create your views here.
def idol_index(request):
idols = Idol.objects.all()
objs = {}
if "q" in request.GET:
q = request.GET['q']
idols = Idol.objects.filter(name__icontains=q) | Idol.objects.filter(
romanized_name__icontains=q)
objs['q'] = q
objs['idols'] = idols
return render(request, 'idols/index.html', objs)
def idol_show(request, id):
idol = Idol.objects.filter(id=id)[0]
return render(request, 'idols/show.html', {'idol': idol})

View File

@ -3,11 +3,15 @@ from django.contrib import admin
from .models import Song, OutsideSong
from artists.models import Artist
from idols.models import Idol
class SongForm(forms.ModelForm):
lyricist_str = forms.CharField(label='Lyricists', required=False)
composer_str = forms.CharField(label='Composers', required=False)
arranger_str = forms.CharField(label='Arrangers', required=False)
idols_str = forms.CharField(label='Idols', required=False)
class Meta:
model = Song
fields = [
@ -17,33 +21,44 @@ class SongForm(forms.ModelForm):
'lyricist_str',
'composer_str',
'arranger_str',
'idols_str',
'impression',
]
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['impression'].widget.attrs['class'] = 'tm-textfield'
instance = kwargs.get("instance")
if instance:
self.fields['lyricist_str'].initial = ', '.join(x.romanized_name for x in instance.lyricist.all() )
self.fields['composer_str'].initial = ', '.join(x.romanized_name for x in instance.composer.all() )
self.fields['arranger_str'].initial = ', '.join(x.romanized_name for x in instance.arranger.all() )
self.fields['lyricist_str'].initial = ', '.join(
x.romanized_name for x in instance.lyricist.all())
self.fields['composer_str'].initial = ', '.join(
x.romanized_name for x in instance.composer.all())
self.fields['arranger_str'].initial = ', '.join(
x.romanized_name for x in instance.arranger.all())
self.fields['idols_str'].initial = ', '.join(
x.romanized_name for x in instance.idols.all())
class SongAdmin(admin.ModelAdmin):
form = SongForm
search_fields = ['romanized_title','title']
search_fields = ['romanized_title', 'title']
class Media:
js = (
'https://cdnjs.cloudflare.com/ajax/libs/tinymce/5.6.2/tinymce.min.js',
'tinymce-init.js'
)
def save_model(self, request, obj, form, change):
lyricist_str = form.cleaned_data.get('lyricist_str')
composer_str = form.cleaned_data.get('composer_str')
arranger_str = form.cleaned_data.get('arranger_str')
idols_str = form.cleaned_data.get('idols_str')
lyricist = Artist.objects.comma_to_qs(lyricist_str)
composer = Artist.objects.comma_to_qs(composer_str)
arranger = Artist.objects.comma_to_qs(arranger_str)
idols = Idol.objects.comma_to_qs(idols_str)
if not obj.id:
obj.save()
obj.lyricist.clear()
@ -52,10 +67,14 @@ class SongAdmin(admin.ModelAdmin):
obj.composer.add(*composer)
obj.arranger.clear()
obj.arranger.add(*arranger)
obj.idols.clear()
obj.idols.add(*idols)
obj.save()
class OutsideSongAdmin(admin.ModelAdmin):
search_fields = ['title']
admin.site.register(Song, SongAdmin)
admin.site.register(OutsideSong, OutsideSongAdmin)

View File

@ -0,0 +1,19 @@
# Generated by Django 3.2.5 on 2021-07-09 17:11
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('artists', '0005_idol_voiceactor'),
('songs', '0004_auto_20201217_0812'),
]
operations = [
migrations.AddField(
model_name='song',
name='idols',
field=models.ManyToManyField(blank=True, related_name='idol_songs', to='artists.Idol'),
),
]

View File

@ -0,0 +1,19 @@
# Generated by Django 3.2.5 on 2021-07-09 17:20
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('idols', '0001_initial'),
('songs', '0005_song_idols'),
]
operations = [
migrations.AlterField(
model_name='song',
name='idols',
field=models.ManyToManyField(blank=True, related_name='idol_songs', to='idols.Idol'),
),
]

View File

@ -9,6 +9,7 @@ class Song(models.Model):
lyricist = models.ManyToManyField("artists.Artist", blank=True, related_name="written_songs")
composer = models.ManyToManyField("artists.Artist", blank=True, related_name="composed_songs")
arranger = models.ManyToManyField("artists.Artist", blank=True, related_name="arranged_songs")
idols = models.ManyToManyField("idols.Idol",blank=True,related_name="idol_songs")
impression = models.TextField(blank=True)
class Meta: