5

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

我已经定义了我的表单、模型和模型管理员:

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: key "is_featured" not found in form

完整的堆栈跟踪在这里https://dpaste.de/9yV3

任何帮助都感激不尽。谢谢!

4

1 回答 1

1

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

于 2013-10-10T12:24:39.820 回答