1
0
mirror of https://github.com/Damillora/Altessimo synced 2024-11-21 21:47:33 +00:00

Modify some more

This commit is contained in:
Damillora 2020-12-16 14:29:08 +07:00
parent fdbc1e7560
commit d91e794eec
5 changed files with 78 additions and 3 deletions

View File

@ -0,0 +1,23 @@
# Generated by Django 3.1.4 on 2020-12-16 07:24
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('artists', '0003_auto_20201215_2107'),
]
operations = [
migrations.AlterField(
model_name='artist',
name='name',
field=models.CharField(blank=True, max_length=255),
),
migrations.AlterField(
model_name='artist',
name='romanized_name',
field=models.CharField(blank=True, max_length=255),
),
]

View File

@ -2,14 +2,31 @@ from django.db import models
from django.apps import apps
# Create your models here.
class ArtistManager(models.Manager):
def create_or_new(self, romanized_name):
romanized_name = romanized_name.strip()
qs = self.get_queryset().filter(romanized_name__iexact=romanized_name)
if qs.exists():
return qs.first(), False
return Artist.objects.create(romanized_name=romanized_name), True
def comma_to_qs(self, artists_str):
final_ids = []
for artist in artists_str.split(','):
obj, created = self.create_or_new(artist)
final_ids.append(obj.id)
qs = self.get_queryset().filter(id__in=final_ids).distinct()
return qs
class Artist(models.Model):
name = models.CharField(max_length=255)
romanized_name = models.CharField(max_length=255)
name = models.CharField(max_length=255,blank=True)
romanized_name = models.CharField(max_length=255,blank=True)
aliases = models.ManyToManyField("self",blank=True)
category = models.ManyToManyField("categories.Category",blank=True)
about_composer = models.TextField(blank=True)
about_music = models.TextField(blank=True)
objects = ArtistManager()
def __str__(self):
return self.romanized_name

View File

@ -0,0 +1,17 @@
# Generated by Django 3.1.4 on 2020-12-16 07:24
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('categories', '0003_auto_20201215_2107'),
]
operations = [
migrations.AlterModelOptions(
name='category',
options={'verbose_name_plural': 'Categories'},
),
]

View File

@ -1,11 +1,28 @@
from django.db import models
# Create your models here.
class CategoryManager(models.Manager):
def create_or_new(self, name):
name = name.strip()
qs = self.get_queryset().filter(name__iexact=name)
if qs.exists():
return qs.first(), False
return Category.objects.create(name=name), True
def comma_to_qs(self, categorys_str):
final_ids = []
for category in categories_str.split(','):
obj, created = self.create_or_new(category)
final_ids.append(obj.id)
qs = self.get_queryset().filter(id__in=final_ids).distinct()
return qs
class Category(models.Model):
name = models.CharField(max_length=255)
description = models.TextField(blank=True)
objects = CategoryManager()
class Meta:
verbose_name_plural = "Categories"

View File

@ -1,5 +1,6 @@
from django.contrib import admin
from . import models
# Register your models here.
admin.site.register(models.Song)
admin.site.register(models.OutsideSong)