#11148: Inline Views don't support editable=False for PK value
---------------------------------------+------------------------------------
 Reporter:  [email protected]  |       Owner:  nobody    
   Status:  new                        |   Milestone:  1.1       
Component:  django.contrib.admin       |     Version:  SVN       
 Keywords:                             |       Stage:  Unreviewed
Has_patch:  0                          |  
---------------------------------------+------------------------------------
 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

-- 
Ticket URL: <http://code.djangoproject.com/ticket/11148>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to