#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)
> }}}
>
> 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'
> }}}
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 <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/064.fcb3cbbd6296445827fd7725afe7214d%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.