Opened 13 years ago

Closed 12 years ago

Last modified 12 years ago

#935 closed defect (duplicate)

weird interaction between edit_inline and OneToOneField causes adding through admin to fail

Reported by: David Ascher <david.ascher@…> Owned by: Adrian Holovaty
Component: contrib.admin Version:
Severity: normal Keywords:
Cc: david.ascher@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Adrian Holovaty)

if I take a model like:

class Account(meta.Model):
    user = meta.OneToOneField(auth.User, core=True)
    kid_name = meta.CharField(...)

which extends the User model, and then have:

class Transaction(meta.Model):
    account = meta.ForeignKey(Account)
    value = meta.FloatField(max_digits=10,decimal_places=2, default=0)
    date = meta.DateField(
    note = meta.CharField(maxlength=200, default='')

to associate many transactions w/ each account, everything works fine, including the admin pages.

If I add "edit_inline=True, core=True" to the account ForeignKey description, then creating Accounts through the admin interface fails with an error:

AttributeError at /admin/accounts/accounts/add/
'Account' object has no attribute 'user'
Request Method: 	POST
Request URL: 	http://localhost:8000/admin/accounts/accounts/add/
Exception Type: 	AttributeError
Exception Value: 	'Account' object has no attribute 'user'
Exception Location: 	/Users/davidascher/django/django/core/meta/ in manipulator_save, line 1754

The request object looks like:

<DjangoRequest GET:{}, POST:{'': [], '': 2005-11-27?, 'transaction.2.value': 0?, '_addanother': Save and add another?, '': 2005-11-27?, 'transaction.2.note': [], 'transaction.1.note': [], 'balance_at_last_transaction': 0?, 'last_transaction_date': 2005-11-27?, 'transaction.0.value': 0?, 'currency': CAD?, '': [], 'user': 1?, 'kid_name': asdas?, '': [], '': 2005-11-27?, 'pub_date': 2005-11-27?, 'transaction.1.value': 0?, 'transaction.0.note': []}, COOKIES:{'hotclub': 'a8625192d1938973fe717071e5202194'}, META:{'CONTENT_LENGTH': '420', 'CONTENT_TYPE': 'application/x-www-form-urlencoded', 'DJANGO_SETTINGS_MODULE': 'bankofdad.settings', 'GATEWAY_INTERFACE': 'CGI/1.1', 'GDK_USE_XFT': '1', 'HOME': '/Users/davidascher', 'HTTP_ACCEPT': 'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5', 'HTTP_ACCEPT_CHARSET': 'ISO-8859-1,utf-8;q=0.7,*;q=0.7', 'HTTP_ACCEPT_ENCODING': 'gzip,deflate', 'HTTP_ACCEPT_LANGUAGE': 'en-us,en;q=0.5', 'HTTP_CONNECTION': 'keep-alive', 'HTTP_COOKIE': 'hotclub=a8625192d1938973fe717071e5202194', 'HTTP_HOST': 'localhost:8000', 'HTTP_KEEP_ALIVE': '300', 'HTTP_REFERER': 'http://localhost:8000/admin/accounts/accounts/add/', 'HTTP_USER_AGENT': 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8) Gecko/20051111 Firefox/1.5', 'INFOPATH': '/sw/share/info:/sw/info:/usr/share/info', 'LOGNAME': 'davidascher', 'MANPATH': '/sw/share/man:/opt/local/share/man:/usr/share/man:/usr/X11R6/man', 'OLDPWD': '/Users/davidascher', 'PATH': '/sw/bin:/sw/sbin:/Users/davidascher/bin:/usr/local/bin:/sw/bin:/opt/local/bin:/Users/davidascher/django/django/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin', 'PATH_INFO': '/admin/accounts/accounts/add/', 'PERL5LIB': '/sw/lib/perl5:/sw/lib/perl5/darwin', 'PWD': '/Users/davidascher/svk/trunk/bankofdad', 'PYTHONPATH': '/Users/davidascher/svk/trunk:/Users/davidascher/django', 'QUERY_STRING': , 'REMOTE_ADDR': '', 'REMOTE_HOST': 'django.loc', 'REQUEST_METHOD': 'POST', 'RUN_MAIN': 'true', 'SCRIPT_NAME': , 'SECURITYSESSIONID': '40f690', 'SERVER_NAME': 'django.loc', 'SERVER_PORT': '8000', 'SERVER_PROTOCOL': 'HTTP/1.1', 'SERVER_SOFTWARE': 'WSGIServer/0.1 Python/2.4.1', 'SGML_CATALOG_FILES': '/sw/etc/sgml/catalog', 'SHELL': '/bin/bash', 'SHLVL': '1', 'TERM': 'vt100', 'TERM_PROGRAM': '', 'TZ': 'America/Chicago', 'USER': 'davidascher', 'XML_CATALOG_FILES': '/sw/etc/xml/catalog', '_': '/Users/davidascher/django/django/bin/', 'CF_USER_TEXT_ENCODING': '0x1F5:0:0', 'wsgi.errors': <open file '<stderr>', mode 'w' at 0x120b0>, 'wsgi.file_wrapper': <class django.core.servers.basehttp.FileWrapper at 0x2b1120>, 'wsgi.input': <socket._fileobject object at 0x738260>, 'wsgi.multiprocess': False, 'wsgi.multithread': True, 'wsgi.run_once': False, 'wsgi.url_scheme': 'http', 'wsgi.version': (1, 0)}>

Adding the account through the API works just fine:

>>> u = users.get_list()[0]
>>> a = Account(user=u, kid_name='foo')



Change History (2)

comment:1 Changed 13 years ago by Adrian Holovaty

Description: modified (diff)

(Fixed formatting in description)

comment:2 Changed 12 years ago by Gary Wilson <gary.wilson@…>

Resolution: duplicate
Status: newclosed

Marking this as a duplicate of #1711, where I believe the situation is explained more clearly and with correctly constructed models.

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