2020-12-15 21:32:20 +00:00
|
|
|
from django.db import models
|
|
|
|
from django.apps import apps
|
2020-12-16 17:36:29 +00:00
|
|
|
from django.utils.text import slugify
|
2020-12-15 21:32:20 +00:00
|
|
|
|
|
|
|
# Create your models here.
|
2020-12-16 07:29:08 +00:00
|
|
|
class ArtistManager(models.Manager):
|
|
|
|
def comma_to_qs(self, artists_str):
|
|
|
|
final_ids = []
|
2020-12-17 13:23:55 +00:00
|
|
|
if artists_str:
|
|
|
|
for artist in artists_str.split(','):
|
|
|
|
obj, created = self.get_or_create(romanized_name=artist.strip())
|
|
|
|
final_ids.append(obj.id)
|
|
|
|
qs = self.get_queryset().filter(id__in=final_ids).distinct()
|
|
|
|
return qs
|
|
|
|
return self.none()
|
2020-12-15 21:32:20 +00:00
|
|
|
|
|
|
|
class Artist(models.Model):
|
2020-12-16 07:29:08 +00:00
|
|
|
name = models.CharField(max_length=255,blank=True)
|
2020-12-16 17:36:29 +00:00
|
|
|
romanized_name = models.CharField(max_length=255)
|
|
|
|
slug = models.SlugField(max_length=255,blank=True)
|
2020-12-15 21:32:20 +00:00
|
|
|
aliases = models.ManyToManyField("self",blank=True)
|
|
|
|
category = models.ManyToManyField("categories.Category",blank=True)
|
2020-12-16 17:36:29 +00:00
|
|
|
about_artist = models.TextField(blank=True)
|
2020-12-15 21:32:20 +00:00
|
|
|
about_music = models.TextField(blank=True)
|
2020-12-16 07:29:08 +00:00
|
|
|
|
|
|
|
objects = ArtistManager()
|
2020-12-16 08:51:48 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = [ 'romanized_name','name' ]
|
|
|
|
|
2020-12-15 21:32:20 +00:00
|
|
|
def __str__(self):
|
|
|
|
return self.romanized_name
|
2020-12-16 17:36:29 +00:00
|
|
|
|
|
|
|
def save(self, *args, **kwargs):
|
|
|
|
self.slug = slugify(self.romanized_name)
|
|
|
|
super().save(*args,**kwargs)
|