django admin keyerror:表单中找不到密钥

时间:2013-10-09 17:37:58

标签: python django django-models django-forms django-admin

我的表格在django admin中有一个奇怪的问题。

我已经定义了我的表单,模型和modeladmin:

import datetime
from cmsplugin_news.admin import NewsAdmin as OldNewsAdmin
from django import forms
from django.db import models
from news.models import News


class NewNewsForm(forms.ModelForm):
    class Meta:
        model = News
        fields = ('title', 'is_published', 'pub_date', 'is_featured')


class NewsAdmin(OldNewsAdmin ):
    fields = ('title', 'is_published', 'pub_date', 'is_featured')
    form = NewNewsForm


class News(models.Model):
    title = models.CharField(_('Title'), max_length=255)
    is_published = models.BooleanField(_('Published'), default=False)
    pub_date = models.DateTimeField(_('Publication date'), default=datetime.datetime.now)
    is_featured = models.BooleanField(_('Featured'), default=False)

admin.site.register(News, NewsAdmin)

模型中的所有字段似乎也出现在管理员和表单中。但是当我前往/ en / admin / news / news / 4 /时,我得到以下KeyError:在表单中找不到键“is_featured”

此处的完整堆栈跟踪https://dpaste.de/9yV3

任何帮助将不胜感激。谢谢!

1 个答案:

答案 0 :(得分:1)

似乎与其他财产发生了冲突。更改名称使其有效。