summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorTimo Graham <timograham@gmail.com>2011-02-02 20:57:09 +0000
committerTimo Graham <timograham@gmail.com>2011-02-02 20:57:09 +0000
commitf77d81de3d08c3e441b2fdd168af51a141267493 (patch)
tree626e12a667f96c6769c11a3ccc28496eff5a5c16 /docs
parenta9ebf9ec24dfc4c38e5341e91146cf2ef6f140c0 (diff)
Fixed #15208 - Document ModelAdmin.formfield_for_choice_field; thanks julien.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@15399 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'docs')
-rw-r--r--docs/ref/contrib/admin/index.txt19
1 files changed, 19 insertions, 0 deletions
diff --git a/docs/ref/contrib/admin/index.txt b/docs/ref/contrib/admin/index.txt
index 2815b5ddf2..32668e7b2c 100644
--- a/docs/ref/contrib/admin/index.txt
+++ b/docs/ref/contrib/admin/index.txt
@@ -927,6 +927,25 @@ templates used by the :class:`ModelAdmin` views:
kwargs["queryset"] = Car.objects.filter(owner=request.user)
return super(MyModelAdmin, self).formfield_for_manytomany(db_field, request, **kwargs)
+.. method:: ModelAdmin.formfield_for_choice_field(self, db_field, request, **kwargs)
+
+ Like the ``formfield_for_foreignkey`` and ``formfield_for_manytomany``
+ methods, the ``formfield_for_choice_field`` method can be overridden to
+ change the default formfield for a field that has declared choices. For
+ example, if the choices available to a superuser should be different than
+ those available to regular staff, you could proceed as follows::
+
+ class MyModelAdmin(admin.ModelAdmin):
+ def formfield_for_choice_field(self, db_field, request, **kwargs):
+ if db_field.name == "status":
+ kwargs['choices'] = (
+ ('accepted', 'Accepted'),
+ ('denied', 'Denied'),
+ )
+ if request.user.is_superuser:
+ kwargs['choices'] += (('ready', 'Ready for deployment'),)
+ return super(MyModelAdmin, self).formfield_for_choice_field(db_field, request, **kwargs)
+
.. method:: ModelAdmin.has_add_permission(self, request)
Should return ``True`` if adding an object is permitted, ``False``