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:
parent
c184dc3534
commit
2cc9a7bd31
@ -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)
|
||||||
|
@ -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)
|
||||||
|
Loading…
Reference in New Issue
Block a user