Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django admin keyerror: key not found in form

I have a strange problem with my form in django admin.

I have defined my form, model and 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)

All fields in the model seem to appear as well in the admin and form. But when I head to /en/admin/news/news/4/, I'm getting the following KeyError: key "is_featured" not found in form

Full stacktrace here https://dpaste.de/9yV3

Any help will be much appreciated. Thanks!

like image 277
sogeking Avatar asked Nov 11 '22 20:11

sogeking


1 Answers

It seems there was a collision with other property. Changing the name made it work.

like image 165
sogeking Avatar answered Nov 15 '22 00:11

sogeking