Opened 18 years ago

Last modified 17 years ago

#1939 closed defect

Multiple Foreign Keys breaks the admin — at Initial Version

Reported by: ww@… Owned by: nobody
Component: contrib.admin Version: dev
Severity: critical Keywords:
Cc: gary.wilson@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

A minimal model that reproduces the problem:

class Account(models.Model):

class Admin:

pass

owner = models.CharField(maxlength = 32)


class Transaction(models.Model):

account = models.ForeignKey(Account, core = True, related_name = 'transactions1',

edit_inline = models.TABULAR,
num_in_admin = 1)

contra = models.ForeignKey(Account, related_name = 'transactions2')
description = models.CharField(maxlength = 64)

This code, when run in the admin, and when goes to the Account add screen, produces
the following traceback:

Traceback (most recent call last):
File "/home/ww/django_src/django/template/init.py" in render_node

  1. result = node.render(context)

File "/home/ww/django_src/django/template/defaulttags.py" in render

  1. nodelist.append(node.render(context))

File "/home/ww/django_src/django/contrib/admin/templatetags/admin_modify.py" in render

  1. bound_related_object = relation.bind(contextform, original, bound_related_object_class)

File "/home/ww/django_src/django/db/models/related.py" in bind

  1. return bound_related_object_class(self, field_mapping, original)

File "/home/ww/django_src/django/contrib/admin/templatetags/admin_modify.py" in init

  1. self.form_field_collection_wrappers = [FormFieldCollectionWrapper(field_mapping ,fields, i)

File "/home/ww/django_src/django/contrib/admin/templatetags/admin_modify.py" in init

  1. self.bound_fields = [AdminBoundField(field, self.field_mapping, field_mappingoriginal)

File "/home/ww/django_src/django/contrib/admin/views/main.py" in init

  1. self.form_fields = [field_mapping[name] for name in self.field.get_manipulator_field_names()]

File "/home/ww/django_src/django/forms/init.py" in getitem

  1. return self.formfield_dict[template_key]

KeyError at /admin/record/account/add/
'account'

I am running SVN as of a few minutes ago.

Change History (0)

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