Opened 10 years ago

Closed 9 years ago

#4126 closed (worksforme)

TypeError when edit_inline and Multiple ForeignKeys to same model breaks the admin

Reported by: dan <goldner@…> Owned by: nobody
Component: contrib.admin Version: master
Severity: Keywords: m2m intermediary edit_inline
Cc: smoonen@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


This is almost a duplicate of #1939, however, I am getting a TypeError instead of a KeyError.

Minimal example (a commenter to #2522 had the same use case in mind):

from django.db import models

class Node(models.Model):
    name = models.CharField('Name', maxlength=30, unique=True)   
    def __str__(self):
    class Admin:

class Link(models.Model):
    from_node=models.ForeignKey(Node, related_name='has_links_to', edit_inline=True)
    to_node=models.ForeignKey(Node, related_name='has_links_from', core=True)
    strength=models.FloatField('Strength', max_digits=3, decimal_places=2, core=True)

Trying to add a Node through the Admin gives this traceback (SVN r5061):

Traceback (most recent call last):
File "C:\cygwin\home\Dan\src\django_src\django\template\" in render_node
  723. result = node.render(context)
File "C:\cygwin\home\Dan\src\django_src\django\template\" in render
  125. nodelist.append(node.render(context))
File "C:\cygwin\home\Dan\src\django_src\django\contrib\admin\templatetags\" in render
  170. bound_related_object = relation.bind(context['form'], original, bound_related_object_class)
File "C:\cygwin\home\Dan\src\django_src\django\db\models\" in bind
  129. return bound_related_object_class(self, field_mapping, original)

  TypeError at /admin/ntwk/node/add/
  'bool' object is not callable

Change History (6)

comment:1 Changed 10 years ago by John Shaffer <jshaffer2112@…>

This is the same bug as #4490.

comment:2 Changed 10 years ago by John Shaffer <jshaffer2112@…>

Component: UncategorizedAdmin interface
Owner: changed from Jacob to Adrian Holovaty

comment:3 Changed 9 years ago by Antonis Christofides <anthony@…>

Keywords: edit_inline added

comment:4 Changed 9 years ago by Jacob

Triage Stage: UnreviewedAccepted

comment:5 Changed 9 years ago by Scott Moonen <smoonen@…>

Cc: smoonen@… added

comment:6 Changed 9 years ago by smoonen@…

Resolution: worksforme
Status: newclosed

As expected, this is fixed with the merge of newforms-admin. I verified using my own models (I had to specify the 'fk_name' attribute on my inline class), and everything saves without error.

I am marking this as "worksforme" rather than "fixed" since I'm not the original reporter. Dan, feel free to move this ticket to "fixed", or alternatively the developers are welcome to do so as well.


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