From 177d22da50e7eb068d3c72f78f604492f14eb73a Mon Sep 17 00:00:00 2001 From: Nick Sweeting Date: Mon, 1 Mar 2021 01:39:06 -0500 Subject: [PATCH] fix clicking add tag when no tag is selected throwing 500 --- archivebox/core/admin.py | 8 ++++---- archivebox/core/models.py | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/archivebox/core/admin.py b/archivebox/core/admin.py index 4dbc2ff7..d539d3f1 100644 --- a/archivebox/core/admin.py +++ b/archivebox/core/admin.py @@ -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" diff --git a/archivebox/core/models.py b/archivebox/core/models.py index 72eed2c3..8cd2b1a9 100644 --- a/archivebox/core/models.py +++ b/archivebox/core/models.py @@ -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"