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

Do not add blank string artists and categories if comma-separated string is empty

This commit is contained in:
Damillora 2020-12-17 20:23:55 +07:00
parent c184dc3534
commit 2cc9a7bd31
2 changed files with 14 additions and 10 deletions

View File

@ -6,11 +6,13 @@ from django.utils.text import slugify
class ArtistManager(models.Manager): class ArtistManager(models.Manager):
def comma_to_qs(self, artists_str): def comma_to_qs(self, artists_str):
final_ids = [] final_ids = []
if artists_str:
for artist in artists_str.split(','): for artist in artists_str.split(','):
obj, created = self.get_or_create(romanized_name=artist.strip()) obj, created = self.get_or_create(romanized_name=artist.strip())
final_ids.append(obj.id) final_ids.append(obj.id)
qs = self.get_queryset().filter(id__in=final_ids).distinct() qs = self.get_queryset().filter(id__in=final_ids).distinct()
return qs return qs
return self.none()
class Artist(models.Model): class Artist(models.Model):
name = models.CharField(max_length=255,blank=True) name = models.CharField(max_length=255,blank=True)

View File

@ -14,11 +14,13 @@ class Branch(models.Model):
class CategoryManager(models.Manager): class CategoryManager(models.Manager):
def comma_to_qs(self, categories_str): def comma_to_qs(self, categories_str):
final_ids = [] final_ids = []
if categories_str:
for category in categories_str.split(','): for category in categories_str.split(','):
obj, created = self.get_or_create(name=category.strip()) obj, created = self.get_or_create(name=category.strip())
final_ids.append(obj.id) final_ids.append(obj.id)
qs = self.get_queryset().filter(id__in=final_ids).distinct() qs = self.get_queryset().filter(id__in=final_ids).distinct()
return qs return qs
return self.none()
class Category(models.Model): class Category(models.Model):
name = models.CharField(max_length=255) name = models.CharField(max_length=255)