diff --git a/models.py b/models.py index 4e6cdd0..cbbf394 100644 --- a/models.py +++ b/models.py @@ -262,6 +262,7 @@ class Post(models.Model): my_tags = [] # Create new tags for tag in tags.split(','): + if tag == '': continue tag_slug = slugify(tag) found = False for t in tags_list: @@ -277,6 +278,7 @@ class Post(models.Model): # Add new tags post_tags_list = Tag.objects.filter(post=self.id) for tag in tags.split(','): + if tag == '': continue tag_slug = slugify(tag) found = False for t in post_tags_list: @@ -291,16 +293,20 @@ class Post(models.Model): break # Remove old tags - for t in post_tags_list: - found = False - for tag in tags.split(','): - tag_slug = slugify(tag) - if t.name_slug == tag_slug: - found = True - break - if not found: - # print 'Remove ' + t.name_slug + if tags == '': + for t in post_tags_list: self.tags.remove(t) + else: + for t in post_tags_list: + found = False + for tag in tags.split(','): + tag_slug = slugify(tag) + if t.name_slug == tag_slug: + found = True + break + if not found: + # print 'Remove ' + t.name_slug + self.tags.remove(t) self.save()