fix clicking add tag when no tag is selected throwing 500
This commit is contained in:
parent
76ff789164
commit
177d22da50
2 changed files with 6 additions and 6 deletions
|
@ -49,7 +49,6 @@ from django.contrib.admin.helpers import ActionForm
|
|||
|
||||
class SnapshotActionForm(ActionForm):
|
||||
tag = forms.ModelChoiceField(queryset=Tag.objects.all(), required=False)
|
||||
# pass
|
||||
|
||||
|
||||
class SnapshotAdmin(SearchResultsAdminMixin, admin.ModelAdmin):
|
||||
|
@ -214,9 +213,10 @@ class SnapshotAdmin(SearchResultsAdminMixin, admin.ModelAdmin):
|
|||
delete_snapshots.short_description = "Delete"
|
||||
|
||||
def add_tag(self, request, queryset):
|
||||
tag = request.POST['tag']
|
||||
for obj in queryset:
|
||||
obj.tags.add(tag)
|
||||
if tag and tag.id:
|
||||
tag = request.POST['tag']
|
||||
for obj in queryset:
|
||||
obj.tags.add(tag)
|
||||
|
||||
add_tag.short_description = "Add tag"
|
||||
|
||||
|
|
|
@ -32,8 +32,8 @@ class Tag(models.Model):
|
|||
"""
|
||||
Based on django-taggit model
|
||||
"""
|
||||
name = models.CharField(verbose_name="name", unique=True, blank=False, max_length=100)
|
||||
slug = models.SlugField(verbose_name="slug", unique=True, blank=True, max_length=100)
|
||||
name = models.CharField(unique=True, blank=False, max_length=100)
|
||||
slug = models.SlugField(unique=True, blank=True, max_length=100)
|
||||
|
||||
class Meta:
|
||||
verbose_name = "Tag"
|
||||
|
|
Loading…
Reference in a new issue