Opened 18 years ago

Closed 16 years ago

#1603 closed defect (invalid)

Setting a primary key field editable=False breaks when using edit_inline

Reported by: anonymous Owned by: nobody
Component: contrib.admin Version: dev
Severity: normal Keywords: edit_inline
Cc: david@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Setting a primary key field editable=False breaks inline editing. Given the following models:

class FooOne(models.Model):
    id = models.AutoField(primary_key=True, editable=False)
    foobar = models.CharField(maxlength=24, core=True)
    class Admin:
        pass

    def __repr__(self):
        return self.foobar

class FooMany(models.Model):
    id = models.AutoField(primary_key=True, editable=False)
    foo = models.CharField(maxlength=24, core=True)
    fooone = models.ForeignKey(FooOne, edit_inline=models.TABULAR)
    class Admin:
        pass

    def __repr__(self):
        return self.foo

When attempting to update an added FooOne entry via the admin interface, The following error occurs:

Traceback (most recent call last):
File "/usr/lib/python2.4/site-packages/Django-0.91-py2.4.egg/django/core/handlers/base.py" in get_response
  73. response = callback(request, *callback_args, **callback_kwargs)
File "/usr/lib/python2.4/site-packages/Django-0.91-py2.4.egg/django/contrib/admin/views/decorators.py" in _checklogin
  54. return view_func(request, *args, **kwargs)
File "/usr/lib/python2.4/site-packages/Django-0.91-py2.4.egg/django/views/decorators/cache.py" in _wrapped_view_func
  40. response = view_func(request, *args, **kwargs)
File "/usr/lib/python2.4/site-packages/Django-0.91-py2.4.egg/django/contrib/admin/views/main.py" in change_stage
  328. new_object = manipulator.save(new_data)
File "/usr/lib/python2.4/site-packages/Django-0.91-py2.4.egg/django/db/models/manipulators.py" in save
  164. if rel_new_data[related.opts.pk.name][0]:

  KeyError at /admin/trak/fooone/1/
  'id'

The rel_new_data variable at this point contains:

{'foo': ['oof']}

Obviously, an 'id' key is expected. When I change the model of FooMany, so that the 'id' field is editable, I am able to update FooOne successfully via the admin interface.

Change History (4)

comment:1 by Gary Wilson <gary.wilson@…>, 17 years ago

Keywords: editable removed
Summary: Setting a primary key field editable=False breaks inline editing.Setting a primary key field editable=False breaks when using edit_inline
Triage Stage: UnreviewedAccepted

changed summary to include "edit_inline". see also #2434.

comment:2 by Adrian Holovaty, 17 years ago

Version: magic-removalSVN

comment:3 by James Bennett, 16 years ago

#5693 was marked as a duplicate.

comment:4 by Brian Rosner, 16 years ago

Resolution: invalid
Status: newclosed

This should be fixed in 1.0. Marking invalid now.

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