Opened 17 years ago

Closed 17 years ago

Last modified 17 years ago

#7112 closed (invalid)

Ordering in admin breaks changelist

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

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.

Change History (4)

comment:1 by Mike H <mike@…>, 17 years ago

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 by Mike H <mike@…>, 17 years ago

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

comment:3 by Alex Gaynor, 17 years ago

Resolution: invalid
Status: newclosed

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 by Alex Gaynor, 17 years ago

Err that's supposed to be parent__id

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