Opened 9 years ago

Closed 9 years ago

Last modified 9 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 Holovaty)

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.

Change History (8)

comment:1 Changed 9 years ago by Adrian Holovaty

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

(Fixed formatting in description.)

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

Triage Stage: UnreviewedAccepted

Yep. Confirmed on r4921.

comment:3 Changed 9 years ago by Malcolm Tredinnick

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 9 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 9 years ago by anonymous

Cc: None added
Keywords: None added; self-reference list_display removed
Summary: Self-referencing keys in the list_display kills development server with no error thrownNone
Triage Stage: AcceptedDesign decision needed
Version: SVNother branch

comment:6 Changed 9 years ago by Ramiro Morales

Keywords: self-reference list_display added; None removed
Summary: NoneSelf-referencing keys in the list_display kills development server with no error thrown
Triage Stage: Design decision neededAccepted
Version: other branchSVN

Undo anonymous breakage

comment:7 Changed 9 years ago by Ramiro Morales

Resolution: duplicate
Status: newclosed

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 9 years ago by Ramiro Morales

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.

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