django-taggit: make the tags not required in the admin

Question:

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?

Asked By: jammon

||

Answers:

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

blank – Controls whether this field is
required

… at least that’s what the docs say.

Answered By: arie

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
Answered By: Steve Pepple
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.