#253 closed defect (duplicate)
Admin add interface is looking for key that doesn't exist
| Reported by: | 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: | no | UI/UX: | no |
Description
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/base.py", line 63, in get_response
return callback(request, **param_dict)
File "/usr/lib/python2.4/site-packages/django/views/admin/main.py", line 768, in add_stage
new_object = manipulator.save(new_data)
File "/usr/lib/python2.4/site-packages/django/utils/functional.py", 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/__init__.py", line 1414, in manipulator_save
obj_list = DotExpandedDict(new_data.data)[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 polls.py
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 self.pub_date.date() == datetime.date.today()
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.TextField('question'),
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 by , 20 years ago
comment:2 by , 20 years ago
| Resolution: | → duplicate |
|---|---|
| Status: | new → closed |
Ah, so then this is a duplicate of #211.
I located the problematic line:
changing it to:
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.