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

只愿长相守 提交于 2019-12-06 17:12:13

问题


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?


回答1:


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

blank – Controls whether this field is required

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



来源:https://stackoverflow.com/questions/6320686/django-taggit-make-the-tags-not-required-in-the-admin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!