Opened 17 years ago
Closed 13 years ago
#7309 closed Bug (fixed)
NFA: Don't override order_by if no default ordering is specified
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | contrib.admin | Version: | dev |
Severity: | Normal | Keywords: | order_by nfa-someday |
Cc: | simon@…, zerok@… | Triage Stage: | Design decision needed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
newforms-admin has this incredibly useful feature where it allowas you to override the modelAdmin's queryset method like this:
def queryset(self, request): return Chain.objects.all().order_by('treeid', 'level')
And there, you already see the problem: Newforms-admin always changes the order_by clause, even if nothing else was specified in model.Meta or in it's modelAdmin class, or via a GET parameter. This makes it impossible to have the queryset from the aformentioned method presorted.
The reason I need it is quite simple, I need to sort with two or more fields, and nfa only support sorting by one single field :/
So far, I have no idea how to overcome this.
Change History (11)
comment:1 by , 16 years ago
Keywords: | nfa-someday added |
---|
comment:2 by , 16 years ago
Cc: | added |
---|
comment:3 by , 16 years ago
Cc: | added |
---|
comment:4 by , 16 years ago
I just tried it again with newforms-admin as of commit 7875, but it still doesn't do the ordering properly in the admin interface.
comment:5 by , 16 years ago
milestone: | → 1.0 |
---|---|
Triage Stage: | Unreviewed → Design decision needed |
comment:6 by , 16 years ago
milestone: | 1.0 → post-1.0 |
---|---|
Version: | newforms-admin → SVN |
Since you can override queryset()
to get initial multi-field ordering, I'm punting this to at least post-1.0.
comment:7 by , 16 years ago
The problem seems to be that in ChangeList.get_query_set an ordering is added to the queryset, ignoring an already applied one. This just clears the previous ordering.
class QuerySet(object): ... def order_by(self, *field_names): """ Returns a new QuerySet instance with the ordering changed. """ assert self.query.can_filter(), \ "Cannot reorder a query once a slice has been taken." obj = self._clone() obj.query.clear_ordering() obj.query.add_ordering(*field_names) return obj
comment:10 by , 14 years ago
Severity: | → Normal |
---|---|
Type: | → Bug |
Is this even valid anymore? From what I can see in the ModelAdmin class, ordering is now handled using the
ordering
class-element, which can be any list/tuple (I think this happened somewhere around #7484):
{{
}}