Code

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#7112 closed (invalid)

Ordering in admin breaks changelist

Reported by: Mike H <mike@…> Owned by: nobody
Component: contrib.admin Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

I have a very simple model :

class Forum(models.Model):

title = models.CharField(max_length=100)
slug = models.SlugField()
parent = models.ForeignKey('self', blank=True, null=True, related_name='child')
description = models.TextField()
threads = models.IntegerField(default=0)
posts = models.IntegerField(default=0)
class Admin:

ordering = ['parent','title']

Since the qsrf branch was merged, I can add new forums, but the lists of forums when viewing the changelist is empty. The total number of forums reported at the changelist footer is correct though. I am running revision 7501 with a mysql backend. If I replace the ordering with a simple 'pass' everything is fine, although the list is not ordered as I wanted it.

Attachments (0)

Change History (4)

comment:1 Changed 6 years ago by Mike H <mike@…>

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

Sorry, should have previewed that... Here's the model again.

class Forum(models.Model):
    """
    Very basic outline for a Forum, or group of threads. The threads
    and posts fielsd are updated by the save() methods of their
    respective models and are used for display purposes.

    All of the parent/child recursion code here is borrowed directly from
    the Satchmo project: http://www.satchmoproject.com/
    """
    title = models.CharField(max_length=100)
    slug = models.SlugField()
    parent = models.ForeignKey('self', blank=True, null=True, related_name='child')
    description = models.TextField()
    threads = models.IntegerField(default=0)
    posts = models.IntegerField(default=0)
    class Admin:
        ordering = ['parent','title']

comment:2 Changed 6 years ago by Mike H <mike@…>

Investigating a bit more, it's the ordering by the self referential foreignkey that breaks things.

comment:3 Changed 6 years ago by Alex

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

From Malcolm:
That code was already broken, but you just hadn't noticed. Django is now correctly reporting the error. If you order by the parent, then the parents should be order by their parents and so on. Since that's impossible to encode in SQL, previous versions of Django were returning only a single level of ordering, which was very inconsistent.

Either remove the infinite loop or use order_by('parentid') if you want a workaround to simulate the previous ambiguous behaviour.

comment:4 Changed 6 years ago by Alex

Err that's supposed to be parent__id

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.