﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
11148	Inline Views don't support editable=False for PK value	mwilson@…	nobody	"When saving the ''second'' record of a !ManyToMany relationship via the Admin forms using an intermediate model with the pk field parameter of editable=False in the xref table throws this error:
 	/usr/lib/python2.5/site-packages/django/forms/models.py in save_existing_objects, line 621  !KeyError (None)

Steps to reproduce:
   * using the models.py provided below generate your db models (I'm using Postgres).
   * Create a few Entries, Blogs, Authors (manually enter the PK values as made up integers)
   * Using the Inline Entry view of the Authors Add Record screen and attempt to link two Entries to a single author.
      * The first entry will save, the second will throw the error above (!KeyError)

== models.py ==
{{{
from django.db import models
from django.forms import ModelForm
from django.contrib import admin

class Blog(models.Model):
    pk_blog = models.IntegerField(primary_key=True, db_column=""pk_blog"", null=True)
    name = models.CharField(max_length=100)
    tagline = models.TextField()

    def __unicode__(self):
        return ""[%s] %s"" % (self.pk_blog, self.name)
    
    class Meta:
        db_table = 'blog'

    class Admin:
        pass

class Author(models.Model):
    pk_author = models.IntegerField(primary_key=True, db_column=""pk_author"", null=True)
    name = models.CharField(max_length=50)
    email = models.EmailField()

    class Meta:
        db_table = 'author'

    def __unicode__(self):
        return ""[%s] %s"" % (self.pk_author, self.name,)

    class Admin:
        pass

class Entry(models.Model):
    pk_entry = models.IntegerField(primary_key=True, db_column=""pk_entry"", null=True)
    pk_blog = models.ForeignKey(Blog, db_column=""pk_blog"", to_field=""pk_blog"")
    headline = models.CharField(max_length=100)
    authors = models.ManyToManyField(Author, through='EntryAuthor')

    def __unicode__(self):
        return ""[%s] %s"" % (self.pk_entry, self.headline,)

    class Meta:
        db_table = 'entry'

    class Admin:
        pass

class EntryAuthor(models.Model):
    # editable line = false will thrown an error on the second record saved per author.
    pk_entry_author = models.IntegerField(primary_key=True, db_column=""pk_entry_author"", null=True, editable=False)
    pk_entry = models.ForeignKey(Entry, db_column=""pk_entry"")
    pk_author = models.ForeignKey(Author, db_column=""pk_author"")
    
    class Meta:
        db_table = 'entry_author'
        
    def __unicode__(self):
        return u'[%s]' % (self.pk_entry_author)

    class Admin:
        pass 

class EntryAuthorInline(admin.TabularInline):
        model = EntryAuthor
        extra = 1

}}}


Env:
   * Postgres 8.3
   * Tested on Linux (FC8 and Ubuntu 9.04)
   * Apache 2 (wsgi)
   * Django Trunk: svn rev 10801
"		closed	contrib.admin	dev		invalid			Unreviewed	0	0	0	0	0	0
