[Django] #25790: Admin magic change list UI ordering is too helpful?

20 views
Skip to first unread message

Django

unread,
Nov 20, 2015, 7:26:36 PM11/20/15
to django-...@googlegroups.com
#25790: Admin magic change list UI ordering is too helpful?
-------------------------------------+-------------------------------------
Reporter: ramiro | Owner: nobody
Type: New | Status: new
feature |
Component: | Version: 1.8
contrib.admin | Keywords: sorting ordering
Severity: Normal | change list changelist admin
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Consider this model:

{{{
# models.py
from __future__ import unicode_literals

from django.db import models


class CreditCard(models.Model):
issued_to = models.CharField(max_length=40)
valid_to = models.DateField()
last_four_digits = models.CharField(max_length=4)
}}}

And this admin.py for the app:
{{{
from django.contrib import admin

from app.models import CreditCard


class CCAdmin(admin.ModelAdmin):
list_display = [
'issued_to',
'valid_to',
'last_four_digits',
]
ordering = ['valid_to']

def last4digits(self, obj):
"""So we don't get bogus ordering by this field in the change list
view."""
return obj.last_four_digits
last4digits.short_description = '4 last digits'


admin.site.register(CreditCard, CCAdmin)
}}}

The user has specified explicitly he/she wants the change list view grid
to be sortable by default by the credt card expiration date by using the
`ModelAdmin.ordering`option.

Now, the interactive sorting changelist functionality that allows one to
sort by a column by clicking on its header automagically allows one to
also sort by other columns chosen by a documented logic (i.e. not if
callable columns, etc.).

In the example, it allows users to also sort by the name of the credit
card owner which, even if not asked for, seems useful.

Where it doesn't make so much sense is, for the example, in the case of
the 'last four digits' column. IMHO there should be a way to express which
columns one wants this functionality without having to resort to things
like

{{{
class CCAdmin(admin.ModelAdmin):
list_display = [
'issued_to',
'valid_to',
'last4digits',
]
#...

def last4digits(self, obj):
"""So we don't get bogus ordering by this field in the change list
view."""
return obj.last_four_digits
last4digits.short_description = '4 last digits'
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/25790>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Nov 20, 2015, 7:27:38 PM11/20/15
to django-...@googlegroups.com
#25790: Admin magic change list UI ordering is too helpful?
-------------------------------------+-------------------------------------
Reporter: ramiro | Owner: nobody
Type: New feature | Status: new
Component: contrib.admin | Version: 1.8
Severity: Normal | Resolution:
Keywords: sorting ordering | Triage Stage:
change list changelist admin | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by ramiro:

Old description:

New description:

Consider this model:

{{{
# models.py
from __future__ import unicode_literals

from django.db import models


class CreditCard(models.Model):
issued_to = models.CharField(max_length=40)
valid_to = models.DateField()
last_four_digits = models.CharField(max_length=4)
}}}

And this admin.py for the app:
{{{
from django.contrib import admin

from app.models import CreditCard


class CCAdmin(admin.ModelAdmin):
list_display = [
'issued_to',
'valid_to',
'last_four_digits',
]
ordering = ['valid_to']


admin.site.register(CreditCard, CCAdmin)
}}}

--

--
Ticket URL: <https://code.djangoproject.com/ticket/25790#comment:1>

Django

unread,
Nov 20, 2015, 8:17:54 PM11/20/15
to django-...@googlegroups.com
#25790: Admin magic change list UI ordering is too helpful?
-------------------------------------+-------------------------------------
Reporter: ramiro | Owner: nobody
Type: New feature | Status: new
Component: contrib.admin | Version: 1.8
Severity: Normal | Resolution:
Keywords: sorting ordering | Triage Stage:
change list changelist admin | Unreviewed
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by ramiro):

* needs_docs: 0 => 1
* has_patch: 0 => 1
* needs_tests: 0 => 1


Comment:

There is some work in this branch:
https://github.com/django/django/compare/master...ramiro:ticket_25790?expand=1

I'm thinking now it's wrong or at least incomplete.

I suspect this is overloading the `ModelAdmin.ordering` option (which is
for specifying the change list default/initial ordering) with an
additional function.

A possible solution, provided the feature proposed by this ticket is
accepted, is to have another option e.g. `orderable_by` which when not
provided makes things behave like they do now and when specified (a list
of fields) is ORed with `ordering` to get the final list of columns which
will actually be allowed to sort by.

--
Ticket URL: <https://code.djangoproject.com/ticket/25790#comment:2>

Django

unread,
Nov 21, 2015, 11:21:16 AM11/21/15
to django-...@googlegroups.com
#25790: Add a way to disable column sorting in the admin

-------------------------------------+-------------------------------------
Reporter: ramiro | Owner: nobody
Type: New feature | Status: new
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: sorting ordering | Triage Stage: Accepted
change list changelist admin |

Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* stage: Unreviewed => Accepted
* version: 1.8 => master


Comment:

I guess we should add the the `get_orderable_by(request)` version too.

--
Ticket URL: <https://code.djangoproject.com/ticket/25790#comment:3>

Django

unread,
Feb 9, 2016, 9:18:27 AM2/9/16
to django-...@googlegroups.com
#25790: Add a way to disable column sorting in the admin
-------------------------------------+-------------------------------------
Reporter: ramiro | Owner: sasha0
Type: New feature | Status: assigned

Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: sorting ordering | Triage Stage: Accepted
change list changelist admin |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by sasha0):

* owner: nobody => sasha0
* needs_docs: 1 => 0
* status: new => assigned
* needs_tests: 1 => 0


Comment:

[https://github.com/django/django/pull/6107 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/25790#comment:4>

Django

unread,
Mar 9, 2016, 7:51:56 PM3/9/16
to django-...@googlegroups.com
#25790: Add a way to disable column sorting in the admin
-------------------------------------+-------------------------------------
Reporter: ramiro | Owner: sasha0
Type: New feature | Status: assigned
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: sorting ordering | Triage Stage: Accepted
change list changelist admin |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/25790#comment:5>

Django

unread,
Apr 16, 2016, 5:15:22 AM4/16/16
to django-...@googlegroups.com
#25790: Add a way to disable column sorting in the admin
-------------------------------------+-------------------------------------
Reporter: ramiro | Owner: sasha0
Type: New feature | Status: assigned
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: sorting ordering | Triage Stage: Accepted
change list changelist admin |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by sasha0):

* needs_better_patch: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/25790#comment:6>

Django

unread,
Jun 2, 2016, 3:50:17 PM6/2/16
to django-...@googlegroups.com
#25790: Add a way to disable column sorting in the admin
-------------------------------------+-------------------------------------
Reporter: ramiro | Owner: sasha0
Type: New feature | Status: assigned
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: sorting ordering | Triage Stage: Ready for
change list changelist admin | checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by phildini):

* stage: Accepted => Ready for checkin


Comment:

The PR looks good to me: the patch submitter has answered all questions,
added tests, and all checks pass.

--
Ticket URL: <https://code.djangoproject.com/ticket/25790#comment:7>

Django

unread,
Jun 2, 2016, 5:01:09 PM6/2/16
to django-...@googlegroups.com
#25790: Add a way to disable column sorting in the admin
-------------------------------------+-------------------------------------
Reporter: ramiro | Owner: sasha0
Type: New feature | Status: assigned
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: sorting ordering | Triage Stage: Accepted
change list changelist admin |
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by charettes):

* needs_better_patch: 0 => 1

* needs_docs: 0 => 1

* stage: Ready for checkin => Accepted


Comment:

The documentation requires adjustments as the feature didn't make it in
1.10.

--
Ticket URL: <https://code.djangoproject.com/ticket/25790#comment:8>

Django

unread,
Aug 22, 2016, 9:11:46 PM8/22/16
to django-...@googlegroups.com
#25790: Add a way to disable column sorting in the admin
-------------------------------------+-------------------------------------
Reporter: ramiro | Owner: sasha0
Type: New feature | Status: assigned
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: sorting ordering | Triage Stage: Accepted
change list changelist admin |
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by ramiro:

Old description:

> Consider this model:


>
> {{{
> # models.py
> from __future__ import unicode_literals
>
> from django.db import models
>

> class CreditCard(models.Model):
> issued_to = models.CharField(max_length=40)
> valid_to = models.DateField()
> last_four_digits = models.CharField(max_length=4)
> }}}
>
> And this admin.py for the app:
> {{{
> from django.contrib import admin
>
> from app.models import CreditCard
>

> class CCAdmin(admin.ModelAdmin):
> list_display = [
> 'issued_to',
> 'valid_to',
> 'last_four_digits',
> ]
> ordering = ['valid_to']
>

> admin.site.register(CreditCard, CCAdmin)

New description:

Consider this model:

{{{
# models.py
from __future__ import unicode_literals

from django.db import models


class CreditCard(models.Model):
issued_to = models.CharField(max_length=40)

good_thru = models.DateField()
last_four_digits = models.CharField(max_length=4)
}}}

And this admin.py for the app:
{{{
from django.contrib import admin

from app.models import CreditCard


class CCAdmin(admin.ModelAdmin):
list_display = [
'issued_to',

'good_thru',
'last_four_digits',
]
ordering = ['good_thru']


admin.site.register(CreditCard, CCAdmin)
}}}

The user has specified explicitly he/she wants the change list view grid
to be sortable by default by the credt card expiration date by using the
`ModelAdmin.ordering`option.

Now, the interactive sorting changelist functionality that allows one to
sort by a column by clicking on its header automagically allows one to
also sort by other columns chosen by a documented logic (i.e. not if
callable columns, etc.).

In the example, it allows users to also sort by the name of the credit
card owner which, even if not asked for, seems useful.

Where it doesn't make so much sense is, for the example, in the case of
the 'last four digits' column.

IMHO there should be a way to express which columns one wants this

functionality for without having to resort to things like:

{{{
class CCAdmin(admin.ModelAdmin):
list_display = [
'issued_to',

'good_thru',
'last4digits',
]
#...

def last4digits(self, obj):
"""So we don't get bogus ordering by this field in the change list
view."""
return obj.last_four_digits
last4digits.short_description = '4 last digits'
}}}

--

--
Ticket URL: <https://code.djangoproject.com/ticket/25790#comment:9>

Django

unread,
Mar 3, 2017, 6:02:10 PM3/3/17
to django-...@googlegroups.com
#25790: Add a way to disable column sorting in the admin
-------------------------------------+-------------------------------------
Reporter: Ramiro Morales | Owner: Simon
| Charette

Type: New feature | Status: assigned
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: sorting ordering | Triage Stage: Accepted
change list changelist admin |
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

* owner: Sasha Gaevsky => Simon Charette
* cc: Simon Charette (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/25790#comment:10>

Django

unread,
Dec 12, 2017, 9:29:12 AM12/12/17
to django-...@googlegroups.com
#25790: Add a way to disable column sorting in the admin
-------------------------------------+-------------------------------------
Reporter: Ramiro Morales | Owner: Simon
| Charette
Type: New feature | Status: assigned
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: sorting ordering | Triage Stage: Accepted
change list changelist admin |
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Matthijs Kooijman):

* cc: Matthijs Kooijman (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/25790#comment:11>

Django

unread,
Jan 3, 2018, 1:48:07 PM1/3/18
to django-...@googlegroups.com
#25790: Add a way to disable column sorting in the admin
-------------------------------------+-------------------------------------
Reporter: Ramiro Morales | Owner: Ramiro
| Morales

Type: New feature | Status: assigned
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: sorting ordering | Triage Stage: Accepted
change list changelist admin |
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Ramiro Morales):

* owner: Simon Charette => Ramiro Morales


Comment:

I'm working on updating this.

--
Ticket URL: <https://code.djangoproject.com/ticket/25790#comment:12>

Django

unread,
Jan 3, 2018, 10:48:53 PM1/3/18
to django-...@googlegroups.com
#25790: Add a way to disable column sorting in the admin
-------------------------------------+-------------------------------------
Reporter: Ramiro Morales | Owner: Ramiro
| Morales
Type: New feature | Status: assigned
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: sorting ordering | Triage Stage: Accepted
change list changelist admin |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Ramiro Morales):

* needs_better_patch: 1 => 0


* needs_docs: 1 => 0


Comment:

[https://github.com/django/django/pull/9538 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/25790#comment:13>

Django

unread,
Jan 17, 2018, 9:50:59 AM1/17/18
to django-...@googlegroups.com
#25790: Add a way to disable column sorting in the admin
-------------------------------------+-------------------------------------
Reporter: Ramiro Morales | Owner: Ramiro
| Morales
Type: New feature | Status: assigned
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: sorting ordering | Triage Stage: Ready for
change list changelist admin | checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/25790#comment:14>

Django

unread,
Feb 7, 2018, 6:10:30 PM2/7/18
to django-...@googlegroups.com
#25790: Add a way to disable column sorting in the admin
-------------------------------------+-------------------------------------
Reporter: Ramiro Morales | Owner: Ramiro
| Morales
Type: New feature | Status: closed
Component: contrib.admin | Version: master
Severity: Normal | Resolution: fixed

Keywords: sorting ordering | Triage Stage: Ready for
change list changelist admin | checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"ef2512b2ffdb719e5c0fb82142f9ce8478282823" ef2512b2]:
{{{
#!CommitTicketReference repository=""
revision="ef2512b2ffdb719e5c0fb82142f9ce8478282823"
Fixed #25790 -- Allowed disable column sorting in the admin changelist.

Thanks Ramiro Morales for completing the patch.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/25790#comment:15>

Reply all
Reply to author
Forward
0 new messages