#7942 closed (fixed)
Admin doc does not reflect the fact that In multi-column ordering, only the first column is used.
Reported by: | Martin Diers | Owned by: | MattBowen |
---|---|---|---|
Component: | Documentation | Version: | dev |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
When setting the ordering property in the ModelAdmin class for a model, to a multiple column tuple, the resulting order is not correct.
In my case, I am working with an MPTT tree, such that I have tree_id, level, and lft properties, which I am using to sort.
Here is my ModelAdmin class:
class PageOptions(ModelAdmin): list_display = ('name', 'page_url', 'description','tree_id', 'level', 'lft') ordering = ('tree_id','level','lft',) fieldsets = ( ('Content', {'fields': ('name','title','description','page_url','content','template','menu_text', 'other_menu_text')}), ('MPTT', {'fields': ('lft','rght','tree_id','level'), 'classes': ('collapse','wide')}), )
Here is my Model:
class Page(models.Model): name = models.CharField(max_length=25) title = models.CharField(max_length=80,null=True) description = models.TextField(null=True) menu_text = models.CharField(max_length=25, null=True, blank=True, help_text="Leave blank to exclude from menu.") other_menu_text = models.CharField(max_length=25, null=True, blank=True, help_text="Assigns this page to an alternate menu. Leave blank to exclude from menu.") page_url = models.CharField(max_length=20, unique=True) template = models.ForeignKey(Template, limit_choices_to = {'page_template': True}) content = models.TextField() # The following fields are for implementing MPTT parent = models.ForeignKey('self', null=True, blank=True, related_name='children') lft = models.PositiveIntegerField(null=True, blank=True) rght = models.PositiveIntegerField(null=True, blank=True) tree_id = models.PositiveIntegerField(null=True, blank=True) level = models.PositiveIntegerField(null=True, blank=True) class Meta: ordering = ('tree_id','level','lft',) def __unicode__(self): return self.name def get_absolute_url(self): path = list(self.get_ancestors().values_list('page_url', flat=True)) path.append(self.page_url) return "/" + "/".join(path)
And this is the sort I am getting:
tree level lft 2 0 1 3 1 4 3 0 1 3 1 6 3 1 2 4 0 1
As you can see, it is sorting on the first column, and ignoring the other two. I tried this with and without the ordering property in the model's Meta class.
This may be related to #7309.
Attachments (1)
Change History (7)
comment:1 by , 16 years ago
Component: | Admin interface → Documentation |
---|---|
Summary: | Admin: In multi-column ordering, only the first column is used. → Admin doc does not reflect the fact that In multi-column ordering, only the first column is used. |
comment:2 by , 16 years ago
milestone: | → 1.0 beta |
---|---|
Triage Stage: | Unreviewed → Accepted |
It is correct that ChangeList
only works with one field. There is another ticket open for that. One day it will support more than one. It will be a big change since it will involve UI changes as well. Marking as accepted for the docs change.
comment:3 by , 16 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
by , 16 years ago
Attachment: | admin-ordering-7942.diff added |
---|
Added note that admin only respects the first element in a list.
comment:4 by , 16 years ago
Has patch: | set |
---|
comment:5 by , 16 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Looking at the ChangeList.get_ordering() function, it is clear that the admin is ignoring the other columns by design.
This is really a documentation problem, and I am changing the ticket to reflect that.
The admin.txt document states:
Obviously, there should be a note here stating that only the first column is used, and all others are ignored.