mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #12875 -- Added get_ordering to ModelAdmin. Many thanks to Manuel Saelices.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16383 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -704,6 +704,11 @@ subclass::
|
||||
If this isn't provided, the Django admin will use the model's default
|
||||
ordering.
|
||||
|
||||
.. versionadded:: 1.4
|
||||
|
||||
If you need to specify a dynamic order (for example depending on user or
|
||||
language) you can implement a :meth:`~ModelAdmin.get_ordering` method.
|
||||
|
||||
.. versionchanged:: 1.4
|
||||
|
||||
Django honors all elements in the list/tuple; before 1.4, only the first
|
||||
@@ -957,6 +962,22 @@ templates used by the :class:`ModelAdmin` views:
|
||||
instance.save()
|
||||
formset.save_m2m()
|
||||
|
||||
.. method:: ModelAdmin.get_ordering(self, request)
|
||||
|
||||
.. versionadded:: 1.4
|
||||
|
||||
The ``get_ordering`` method takes a``request`` as parameter and
|
||||
is expected to return a ``list`` or ``tuple`` for ordering similiar
|
||||
to the :attr:`ordering` attribute. For example::
|
||||
|
||||
class PersonAdmin(ModelAdmin):
|
||||
|
||||
def get_ordering(self, request):
|
||||
if request.user.is_superuser:
|
||||
return ['name', 'rank']
|
||||
else:
|
||||
return ['name']
|
||||
|
||||
.. method:: ModelAdmin.get_readonly_fields(self, request, obj=None)
|
||||
|
||||
.. versionadded:: 1.2
|
||||
@@ -1053,7 +1074,7 @@ templates used by the :class:`ModelAdmin` views:
|
||||
.. method:: ModelAdmin.formfield_for_foreignkey(self, db_field, request, **kwargs)
|
||||
|
||||
The ``formfield_for_foreignkey`` method on a ``ModelAdmin`` allows you to
|
||||
override the default formfield for a foreign key field. For example, to
|
||||
override the default formfield for a foreign keys field. For example, to
|
||||
return a subset of objects for this foreign key field based on the user::
|
||||
|
||||
class MyModelAdmin(admin.ModelAdmin):
|
||||
|
||||
@@ -73,10 +73,12 @@ documentation for :attr:`~django.contrib.admin.ModelAdmin.list_filter`.
|
||||
Multiple sort in admin interface
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
The admin change list now supports sorting on multiple columns. It respects all
|
||||
elements of the :attr:`~django.contrib.admin.ModelAdmin.ordering` attribute, and
|
||||
sorting on multiple columns by clicking on headers is designed to work similarly
|
||||
to how desktop GUIs do it.
|
||||
The admin change list now supports sorting on multiple columns. It respects
|
||||
all elements of the :attr:`~django.contrib.admin.ModelAdmin.ordering`
|
||||
attribute, and sorting on multiple columns by clicking on headers is designed
|
||||
to work similarly to how desktop GUIs do it. The new hook
|
||||
:meth:`~django.contrib.admin.ModelAdmin.get_ordering` for specifying the
|
||||
ordering dynamically (e.g. depending on the request) has also been added.
|
||||
|
||||
Tools for cryptographic signing
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Reference in New Issue
Block a user