Code

Opened 7 years ago

Closed 6 years ago

Last modified 6 years ago

#3914 closed (duplicate)

Self-referencing keys in the list_display kills development server with no error thrown

Reported by: adamfast@… Owned by: nobody
Component: contrib.admin Version: master
Severity: Keywords: self-reference list_display
Cc: None Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description (last modified by adrian)

If you use this model:

class Page(models.Model):
    title = models.CharField(maxlength=192)
    default = models.BooleanField()
    template = models.CharField(maxlength=256)
    parent = models.ForeignKey('Page')
    sequence = models.IntegerField()
    visible_on_menu = models.BooleanField()
    defined_header = models.CharField(maxlength=256)
    date_of_creation = models.DateTimeField()
    class Admin:
        list_display = ['title','parent','visible_on_menu']

And try to go to the model in the admin interface, the development server just dies. There is no error, it just goes back to a command prompt waiting.

This model is to be used for a newforms-like setup that can have parent/child pages for building heirarchical navigation menus - and it will be handy to see the parent in the display.

Attachments (0)

Change History (8)

comment:1 Changed 7 years ago by adrian

  • Description modified (diff)
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

(Fixed formatting in description.)

comment:2 Changed 7 years ago by Simon G. <dev@…>

  • Triage Stage changed from Unreviewed to Accepted

Yep. Confirmed on r4921.

comment:3 Changed 7 years ago by mtredinnick

Whilst this is something we might be able to fix, the workaround -- and the way the documentation recommends to do this -- is to use "self" instead of "Page" in the ForeignKey.

comment:4 Changed 7 years ago by Simon G. <dev@…>

This might be something that django.core.management.validate could check for and display a warning?

comment:5 Changed 7 years ago by anonymous

  • Cc None added
  • Keywords None added; self-reference list_display removed
  • Summary changed from Self-referencing keys in the list_display kills development server with no error thrown to None
  • Triage Stage changed from Accepted to Design decision needed
  • Version changed from SVN to other branch

comment:6 Changed 7 years ago by Ramiro Morales

  • Keywords self-reference list_display added; None removed
  • Summary changed from None to Self-referencing keys in the list_display kills development server with no error thrown
  • Triage Stage changed from Design decision needed to Accepted
  • Version changed from other branch to SVN

Undo anonymous breakage

comment:7 Changed 6 years ago by ramiro

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

Marking as duplicate of #4212 because a) this ticket has muted on being about the same issue and b) it has a couple of useful comments about things to consider before implementing validation of FK-to-self declarations.

comment:8 Changed 6 years ago by ramiro

Oops, second try: Marking as duplicate of #4212 because a) it has a couple of useful comments about things to consider before implementing validation of FK-to-self declarations and b) this ticket has mutated to being about the same issue.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.