Opened 8 years ago

Closed 7 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:

Description

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):
        return self.name
    class Admin:
        pass

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\__init__.py" in render_node
  723. result = node.render(context)
File "C:\cygwin\home\Dan\src\django_src\django\template\defaulttags.py" in render
  125. nodelist.append(node.render(context))
File "C:\cygwin\home\Dan\src\django_src\django\contrib\admin\templatetags\admin_modify.py" 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\related.py" 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 8 years ago by John Shaffer <jshaffer2112@…>

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

This is the same bug as #4490.

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

  • Component changed from Uncategorized to Admin interface
  • Owner changed from jacob to adrian

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

  • Keywords edit_inline added

comment:4 Changed 7 years ago by jacob

  • Triage Stage changed from Unreviewed to Accepted

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

  • Cc smoonen@… added

comment:6 Changed 7 years ago by smoonen@…

  • Resolution set to worksforme
  • Status changed from new to closed

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.

Thanks!

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