1
0
mirror of https://github.com/Damillora/Altessimo synced 2024-12-25 11:03:45 +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):
def comma_to_qs(self, artists_str):
final_ids = []
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
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()
class Artist(models.Model):
name = models.CharField(max_length=255,blank=True)

View File

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