django-taggit: make the tags not required in the admin
Asked Answered
L

2

23

I've started using django-taggit and it seems to fit the bill. But for me there is still an issue with the admin site:

I included the tags attribute in the ModelAdmin like this:

class MyModel(db.models.Model):
    name = models.CharField(max_length=200)
    tags = TaggableManager()

class MyModelAdmin(admin.ModelAdmin):
    fieldsets = (
        (None, {
            'fields': ('name', 'tags')
        }),
    )

And everything goes as expected. But when I edit a model in the admin, I get an error, if the TagField is empty. The form seems to be happy with just a blank, and that results in no tags being saved (as expected). But an empty tag field triggers the error.

What can I do?

Lightheaded answered 12/6, 2011 at 7:18 Comment(0)
B
49

Did you try tags = TaggableManager(blank=True)?

blank – Controls whether this field is required

... at least that's what the docs say.

Bindman answered 12/6, 2011 at 8:59 Comment(0)
V
0

I'm not sure why, but TaggableManager(blank=True) doesn't work on a model I updated and migrated. Had to add this to the admin form (forms.ModelForm).

self.fields['tags'].required = False
Vivid answered 13/4, 2023 at 18:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.