diff options
| author | Jannis Leidel <jannis@leidel.info> | 2011-06-12 13:04:53 +0000 |
|---|---|---|
| committer | Jannis Leidel <jannis@leidel.info> | 2011-06-12 13:04:53 +0000 |
| commit | f749bb829c715237c33c48c146ae78e1ed23ae71 (patch) | |
| tree | 8c4047c32b76bf6b71d407869b0d8dafa195bb17 /docs | |
| parent | f0adae4c6e857cabdff790d20dff815a37645d6f (diff) | |
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
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/ref/contrib/admin/index.txt | 23 | ||||
| -rw-r--r-- | docs/releases/1.4.txt | 10 |
2 files changed, 28 insertions, 5 deletions
diff --git a/docs/ref/contrib/admin/index.txt b/docs/ref/contrib/admin/index.txt index 8f941299f7..c0ff3c6036 100644 --- a/docs/ref/contrib/admin/index.txt +++ b/docs/ref/contrib/admin/index.txt @@ -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): diff --git a/docs/releases/1.4.txt b/docs/releases/1.4.txt index 65f3dfe050..cc20795ded 100644 --- a/docs/releases/1.4.txt +++ b/docs/releases/1.4.txt @@ -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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
