Opened 7 years ago

Closed 6 years ago

Last modified 4 years ago

#9743 closed (worksforme)

Problem in admin when displaying foreignkey of a model that reference himself

Reported by: daniels Owned by: jdunck
Component: Database layer (models, ORM) Version: 1.0
Severity: Keywords:
Cc: daniels@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: UI/UX:


class Client(models.Model):
  name = models.CharField()

class Module(models.Model):
  client = models.ForeignKey(Client)

class SuperModule(Module):
  sample = models.ForeignKey(Module)

If in the django.admin.contrib, we want to display SuperModule with a
list_display = ('name', 'client')
it will not work unless we remove the foreign key to Module.
It was not tested with the simple code above, but in our complete code.

After some investigation, I found a way where an error occured when doing 'as_sql()' on a
query_set. The error was about an extra parameter to avoid.update(). And some lines below,
the same function call but with a small difference in parenthesis and works OK.

Attachments (1)

query-dedupe.path (897 bytes) - added by daniels 7 years ago.

Download all attachments as: .zip

Change History (5)

Changed 7 years ago by daniels

comment:1 Changed 7 years ago by jacob

  • milestone set to 1.1
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 6 years ago by jdunck

  • Needs tests set
  • Owner changed from nobody to jdunck
  • Status changed from new to assigned


It'd really help if you provided a full example of your models-- for example, related_name would be required. As long as you're there, maybe supply tests-- regressiontests/model_inheritance_regress would be the right place for it.

comment:3 Changed 6 years ago by jacob

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

I can't reproduce this problem.

comment:4 Changed 4 years ago by jacob

  • milestone 1.1 deleted

Milestone 1.1 deleted

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