gpt4 book ai didi

python - django 管理员 keyerror : key not found in form

转载 作者:行者123 更新时间:2023-11-28 18:46:27 26 4
gpt4 key购买 nike

我在 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

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

最佳答案

似乎与其他属性(property)发生了碰撞。更改名称使其有效。

关于python - django 管理员 keyerror : key not found in form,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19278965/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com