Code

Opened 9 years ago

Closed 8 years ago

#520 closed defect (worksforme)

Ordering via foreign key causes multiple display of entries in Admin view

Reported by: andreas Owned by: adrian
Component: contrib.admin Version:
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Ordering via foreign key causes multiple display of entries in Admin view.

For instance:

class ParentClass(meta.Model):
    somevar        = meta.CharField(maxlength=100)
    def __repr__(self):
        return self.somevar
    class META:
        admin      = meta.Admin()
        ordering   = ['somevar']
 
class FirstChild(meta.Model):
    theparent      = meta.ForeignKey(ParentClass)
    myvar          = meta.CharField(maxlength=100)
    def __repr__(self):
        return repr(self.get_theparent()) + "-" + self.myvar
    class META:
        admin      = meta.Admin()
        ordering   = ['theparent']

After entering two ParentClasses, parent1 and parent2, and two FirstChilds of parent1, child1 and child2, the Admin "First childs" view looks like this:

First child 
parent1-child2 
parent1-child1 
parent1-child2 
parent1-child1

2 first childs

Workaround: Add list_display-option:

class FirstChild(meta.Model):
    ...
    class META:
        admin      = meta.Admin(list_display = ('myvar', 'theparent'))
        ordering   = ['theparent']

Attachments (0)

Change History (1)

comment:1 Changed 8 years ago by adrian

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

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.