﻿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
7938	"""Editable = False"" + ""Edit Inline"" in new forms admin"	magneto	Brian Rosner	"An error involved which now seems realted to the editable = false + edit inline

{{{

class HandleOption(models.Model):
      handle_option_id = models.PositiveIntegerField(primary_key=True, editable = false)
      name = models.CharField(max_length=100)

class Product(models.Model):
      product_id = models.PositiveIntegerField(primary_key=True, editable = false)
      name = models.CharField(max_length=100)

class ProductHandling(models.Model):
	product_handling_id = models.PositiveIntegerField(primary_key=True, editable = false)
	product = models.ForeignKey(Product)
	handle_option = models.ForeignKey(HandleOption, core = True)
	
# Admin bits

class ProductHandling_Inline(admin.StackedInline):
	model = ProductHandling

class ProductOptions(admin.ModelAdmin):
	inlines = [ProductHandling_Inline]
}}}

The form renders properly,  However on 'Save' we get a trace back 

{{{
Traceback:
File ""/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/django/core/handlers/base.py"" in get_response
  87.                 response = callback(request, *callback_args, **callback_kwargs)
File ""/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/django/contrib/admin/sites.py"" in root
  155.                 return self.model_page(request, *url.split('/', 2))
File ""/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/django/views/decorators/cache.py"" in _wrapped_view_func
  44.         response = view_func(request, *args, **kwargs)
File ""/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/django/contrib/admin/sites.py"" in model_page
  172.         return admin_obj(request, rest_of_url)
File ""/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/django/contrib/admin/options.py"" in __call__
  251.             return self.change_view(request, unquote(url))
File ""/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/django/contrib/admin/options.py"" in change_view
  550.                 return self.save_change(request, form, inline_formsets)
File ""/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/django/db/transaction.py"" in _commit_on_success
  198.                 res = func(*args, **kw)
File ""/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/django/contrib/admin/options.py"" in save_change
  390.                 formset.save()
File ""/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/django/forms/models.py"" in save
  339.         return self.save_existing_objects(commit) + self.save_new_objects(commit)
File ""/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/django/forms/models.py"" in save_existing_objects
  355.             obj = existing_objects[form.cleaned_data[self.model._meta.pk.attname]]

Exception Type: KeyError at /admin/products/product/647/
Exception Value: None
}}}

The variables at the time of save at the traceback point

{{{
###
# existing_objects
###
{
3221L: <ProductHandling>, 
3222L: <ProductHandling>,
3223L: <ProductHandling>, 
}

###
# form.cleaned_data
###
{'DELETE': False, 'product_handling_id': None, 'handle_option': <HandleOption: [Postprocessing] - frame - Black Metal Frame>} 

###
# self.model._meta.pk.attname
###
product_handling_id

}}}


IF i Take OUT editable

{{{

class ProductHandling(models.Model):
	product_handling_id = models.PositiveIntegerField(primary_key=True)
	product = models.ForeignKey(Product)
	handle_option = models.ForeignKey(HandleOption, core = True)

}}}

All functions well, BUT there is a 'blank' row in the admin form (obviously a <input hidden> but with an attribute Label present)

seems in the edit_inline case where a field is not editable, but is the explicit primary Key (not the usual automatic Primary key), it should be treated in the same fashion as the auto primary key field



"	Uncategorized	closed	contrib.admin	dev	Normal	invalid	newforms-admin		Accepted	0	1	1	0	0	0
