summaryrefslogtreecommitdiff
path: root/docs/ref
diff options
context:
space:
mode:
authorJannis Leidel <jannis@leidel.info>2011-06-12 13:04:53 +0000
committerJannis Leidel <jannis@leidel.info>2011-06-12 13:04:53 +0000
commitf749bb829c715237c33c48c146ae78e1ed23ae71 (patch)
tree8c4047c32b76bf6b71d407869b0d8dafa195bb17 /docs/ref
parentf0adae4c6e857cabdff790d20dff815a37645d6f (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/ref')
-rw-r--r--docs/ref/contrib/admin/index.txt23
1 files changed, 22 insertions, 1 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):