Opened 11 years ago

Closed 11 years ago

Last modified 10 years ago

#253 closed defect (duplicate)

Admin add interface is looking for key that doesn't exist

Reported by: gandalf@… Owned by: Adrian Holovaty
Component: contrib.admin Version:
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


I'm extending tutorial and I've stumbled upon strange behaviour. I added 2 new classes: 'Answer' and 'Exercise'. When I use admin interface to add new 'Exercise' I get following error:

There's been an error:

Traceback (most recent call last):

  File "/usr/lib/python2.4/site-packages/django/core/handlers/", line 63, in get_response
    return callback(request, **param_dict)

  File "/usr/lib/python2.4/site-packages/django/views/admin/", line 768, in add_stage
    new_object =

  File "/usr/lib/python2.4/site-packages/django/utils/", line 3, in _curried
    return args[0](*(args[1:]+moreargs), **dict(kwargs.items() + morekwargs.items()))

  File "/usr/lib/python2.4/site-packages/django/core/meta/", line 1414, in manipulator_save
    obj_list = DotExpandedDict([rel_opts.object_name.lower()].items()

KeyError: 'answer'

I am using development web server. New entries to 'Exercise' do get added, despite the error, I can also edit them, add 'answers ' and update them. Clearing database (mysql4) and using init and install gives the same errors. Also adding new exercises, gives always the samer error.

Here is my code listing:

gandalf@a1200:/home/stat/webroot/anketa/apps/polls/models$ cat
from django.core import meta

# Create your models here.

class Poll(meta.Model):
    fields = (
        meta.CharField('question', maxlength=200),
        meta.DateTimeField('pub_date', 'date published'),
    admin = meta.Admin(
        fields = (
                (None, {'fields': ('question',)}),
                        ('Date information', {'fields': ('pub_date',), 'classes': 'collapse'}),
        list_display = ('question', 'pub_date', 'was_published_today'),
        list_filter = ['pub_date'],

    def __repr__(self):
        return self.question
    def was_published_today(self):
        return ==

class Choice(meta.Model):
    fields = (
        meta.ForeignKey(Poll, edit_inline=True, num_in_admin=3, edit_inline_type=meta.TABULAR),
        meta.CharField('choice', maxlength=200, core=True),
        meta.IntegerField('votes', core=True),
    def __repr__(self):
        return self.choice

class Exercise(meta.Model):
    fields = (
        meta.DateTimeField('pub_date', 'datum naloge'),
        meta.FloatField('order_no', max_digits=2, decimal_places=2),

    admin = meta.Admin()

    def __repr__(self):
        return self.question

class Answer(meta.Model):
    fields = (
        meta.ForeignKey(Exercise, edit_inline=True),
        meta.CharField('answer_desc', maxlength=200, core=True),
        meta.FloatField('entry', max_digits=2, decimal_places=2),

    #admin = meta.Admin()

    def __repr__(self):
        return self.answer_desc

Change History (2)

comment:1 Changed 11 years ago by gandalf@…

I located the problematic line:

        meta.ForeignKey(Exercise, edit_inline=True),

changing it to:

        meta.ForeignKey(Exercise, edit_inline=True, num_in_admin=1, edit_inline_type=meta.TABULAR),

Solved the problem. It seems to me that edit_inline parameter depends also on num_in_admin and edit_inline_type, yet the documentation states that all are optional. I'm not sure which behaviour is right, that all are optional or that the documentation needs to reflect this dependencies.

comment:2 Changed 11 years ago by Jacob

Resolution: duplicate
Status: newclosed

Ah, so then this is a duplicate of #211.

Note: See TracTickets for help on using tickets.
Back to Top