Loading django/contrib/admin/views/main.py +5 −1 Original line number Diff line number Diff line Loading @@ -293,6 +293,10 @@ class ChangeList(six.with_metaclass(RenameChangeListMethods)): order_field = self.get_ordering_field(field_name) if not order_field: continue # No 'admin_order_field', skip it # reverse order if order_field has already "-" as prefix if order_field.startswith('-') and pfx == "-": ordering.append(order_field[1:]) else: ordering.append(pfx + order_field) except (IndexError, ValueError): continue # Invalid ordering specified, skip it. Loading docs/ref/contrib/admin/index.txt +8 −0 Original line number Diff line number Diff line Loading @@ -664,6 +664,14 @@ subclass:: The above will tell Django to order by the ``first_name`` field when trying to sort by ``colored_first_name`` in the admin. .. versionadded:: 1.7 To indicate descending order with ``admin_model_field`` you can use a hyphen prefix on the field name. Using the above example, this would look like:: colored_first_name.admin_order_field = '-first_name' * Elements of ``list_display`` can also be properties. Please note however, that due to the way properties work in Python, setting ``short_description`` on a property is only possible when using the Loading docs/releases/1.7.txt +4 −0 Original line number Diff line number Diff line Loading @@ -292,6 +292,10 @@ Minor features <django.contrib.admin.ModelAdmin.view_on_site>` to control whether or not to display the "View on site" link. * You can specify a descending ordering for a :attr:`ModelAdmin.list_display <django.contrib.admin.ModelAdmin.list_display>` value by prefixing the ``admin_order_field`` value with a hyphen. :mod:`django.contrib.auth` ^^^^^^^^^^^^^^^^^^^^^^^^^^ Loading tests/admin_views/admin.py +2 −1 Original line number Diff line number Diff line Loading @@ -76,7 +76,8 @@ class ChapterXtra1Admin(admin.ModelAdmin): class ArticleAdmin(admin.ModelAdmin): list_display = ('content', 'date', callable_year, 'model_year', 'modeladmin_year') list_display = ('content', 'date', callable_year, 'model_year', 'modeladmin_year', 'model_year_reversed') list_filter = ('date', 'section') view_on_site = False fieldsets = ( Loading tests/admin_views/models.py +5 −0 Original line number Diff line number Diff line Loading @@ -41,6 +41,11 @@ class Article(models.Model): model_year.admin_order_field = 'date' model_year.short_description = '' def model_year_reversed(self): return self.date.year model_year_reversed.admin_order_field = '-date' model_year_reversed.short_description = '' @python_2_unicode_compatible class Book(models.Model): Loading Loading
django/contrib/admin/views/main.py +5 −1 Original line number Diff line number Diff line Loading @@ -293,6 +293,10 @@ class ChangeList(six.with_metaclass(RenameChangeListMethods)): order_field = self.get_ordering_field(field_name) if not order_field: continue # No 'admin_order_field', skip it # reverse order if order_field has already "-" as prefix if order_field.startswith('-') and pfx == "-": ordering.append(order_field[1:]) else: ordering.append(pfx + order_field) except (IndexError, ValueError): continue # Invalid ordering specified, skip it. Loading
docs/ref/contrib/admin/index.txt +8 −0 Original line number Diff line number Diff line Loading @@ -664,6 +664,14 @@ subclass:: The above will tell Django to order by the ``first_name`` field when trying to sort by ``colored_first_name`` in the admin. .. versionadded:: 1.7 To indicate descending order with ``admin_model_field`` you can use a hyphen prefix on the field name. Using the above example, this would look like:: colored_first_name.admin_order_field = '-first_name' * Elements of ``list_display`` can also be properties. Please note however, that due to the way properties work in Python, setting ``short_description`` on a property is only possible when using the Loading
docs/releases/1.7.txt +4 −0 Original line number Diff line number Diff line Loading @@ -292,6 +292,10 @@ Minor features <django.contrib.admin.ModelAdmin.view_on_site>` to control whether or not to display the "View on site" link. * You can specify a descending ordering for a :attr:`ModelAdmin.list_display <django.contrib.admin.ModelAdmin.list_display>` value by prefixing the ``admin_order_field`` value with a hyphen. :mod:`django.contrib.auth` ^^^^^^^^^^^^^^^^^^^^^^^^^^ Loading
tests/admin_views/admin.py +2 −1 Original line number Diff line number Diff line Loading @@ -76,7 +76,8 @@ class ChapterXtra1Admin(admin.ModelAdmin): class ArticleAdmin(admin.ModelAdmin): list_display = ('content', 'date', callable_year, 'model_year', 'modeladmin_year') list_display = ('content', 'date', callable_year, 'model_year', 'modeladmin_year', 'model_year_reversed') list_filter = ('date', 'section') view_on_site = False fieldsets = ( Loading
tests/admin_views/models.py +5 −0 Original line number Diff line number Diff line Loading @@ -41,6 +41,11 @@ class Article(models.Model): model_year.admin_order_field = 'date' model_year.short_description = '' def model_year_reversed(self): return self.date.year model_year_reversed.admin_order_field = '-date' model_year_reversed.short_description = '' @python_2_unicode_compatible class Book(models.Model): Loading