django-taggit:使管理员不需要标签 [英] django-taggit: make the tags not required in the admin

查看:155
本文介绍了django-taggit:使管理员不需要标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开始使用django-taggit,它似乎符合账单。但是对于我来说,管理员网站仍然存在一个问题:



我在ModelAdmin中包含了标签这个:

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

class MyModelAdmin(admin.ModelAdmin):
fieldsets =(
(无,{
'fields'名称','标签')
}),

按照预期。但是当我在管理员中编辑模型时,如果TagField为空,我会收到一个错误。该表单似乎很满意,只是一个空白,这导致没有保存标签(如预期)。但是一个空的标签字段会触发错误。



我可以做什么?

解决方案>

您尝试过 tags = TaggableManager(blank = True)


空白 - 控制此字段是否为
必需


...至少这就是文档说。


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?

解决方案

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

blank – Controls whether this field is required

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

这篇关于django-taggit:使管理员不需要标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆