﻿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
10252	Can't use id as a field name for parent_link in a child model	Karen Tracey	Malcolm Tredinnick	"Given these models:

{{{
class BaseM(models.Model):
    base_name = models.CharField(max_length=100)
    def __unicode__(self):
        return self.base_name

class DerivedM(BaseM):
    id = models.OneToOneField(BaseM, parent_link=True)
    derived_name = models.CharField(max_length=100)
}}}

An attempt to choose ""Add"" for a DerivedM in admin results in:

{{{
Environment:

Request Method: GET
Request URL: http://localhost:8000/admin/multiauto/derivedm/add/
Django Version: 1.1 pre-alpha SVN-9826
Python Version: 2.5.2
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.admin',
 'multiauto']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.middleware.doc.XViewMiddleware',
 'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware')


Traceback:
File ""d:\u\kmt\django\trunk\django\core\handlers\base.py"" in get_response
  86.                 response = callback(request, *callback_args, **callback_kwargs)
File ""d:\u\kmt\django\trunk\django\contrib\admin\sites.py"" in root
  450.                 return self.model_page(request, *url.split('/', 2))
File ""d:\u\kmt\django\trunk\django\views\decorators\cache.py"" in _wrapped_view_func
  44.         response = view_func(request, *args, **kwargs)
File ""d:\u\kmt\django\trunk\django\contrib\admin\sites.py"" in model_page
  469.         return admin_obj(request, rest_of_url)
File ""d:\u\kmt\django\trunk\django\contrib\admin\options.py"" in __call__
  795.             return self.add_view(request)
File ""d:\u\kmt\django\trunk\django\db\transaction.py"" in _commit_on_success
  238.                 res = func(*args, **kw)
File ""d:\u\kmt\django\trunk\django\contrib\admin\options.py"" in add_view
  549.             form = ModelForm(initial=initial)
File ""d:\u\kmt\django\trunk\django\forms\models.py"" in __init__
  212.             self.instance = opts.model()
File ""d:\u\kmt\django\trunk\django\db\models\base.py"" in __init__
  255.                 setattr(self, field.attname, val)
File ""d:\u\kmt\django\trunk\django\db\models\fields\related.py"" in __set__
  265.                                 (instance._meta.object_name, self.field.name))

Exception Type: ValueError at /admin/multiauto/derivedm/add/
Exception Value: Cannot assign None: ""DerivedM.id"" does not allow null values.

}}}

Changing the name of the parent_link=True field to something other than 'id' makes the problem go away.  

This was originally noticed in this thread:

http://groups.google.com/group/django-users/browse_thread/thread/87b8497f23cfb64f#

I don't know if 'id' is disallowed as a field name; if so it would seem better to report that when the model is validated rather than going down in flames later.  If 'id' is allowed, I'm not sure whether it's forms or admin or ORM that is having trouble here...."		closed	Database layer (models, ORM)	1.0		fixed			Accepted	0	0	0	0	0	0
