Opened 19 years ago

Last modified 17 years ago

#1939 closed defect

Multiple Foreign Keys breaks the admin — at Version 2

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 (last modified by Adrian Holovaty)

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
  701. result = node.render(context)
File "/home/ww/django_src/django/template/defaulttags.py" in render
  113. nodelist.append(node.render(context))
File "/home/ww/django_src/django/contrib/admin/templatetags/admin_modify.py" in render
  155. bound_related_object = relation.bind(context['form'], original, bound_related_object_class)
File "/home/ww/django_src/django/db/models/related.py" in bind
  122. return bound_related_object_class(self, field_mapping, original)
File "/home/ww/django_src/django/contrib/admin/templatetags/admin_modify.py" in __init__
  136. self.form_field_collection_wrappers = [FormFieldCollectionWrapper(field_mapping ,fields, i)
File "/home/ww/django_src/django/contrib/admin/templatetags/admin_modify.py" in __init__
  112. self.bound_fields = [AdminBoundField(field, self.field_mapping, field_mapping['original'])
File "/home/ww/django_src/django/contrib/admin/views/main.py" in __init__
  115. 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__
  195. 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 (2)

comment:1 by [530], 19 years ago

Cleaned up the model code

class Account(models.Model):

    owner = models.CharField(maxlength = 32)

    class Admin:
        pass
    
    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)

    class Admin:
        pass


comment:2 by Adrian Holovaty, 19 years ago

Description: modified (diff)

Fixed formatting in description.

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