Commits

Ian Struble committed aff9d87

Added documentation for ModelAdmin.autocomplete_fields.

  • Participants
  • Parent commits 5e1e20f

Comments (0)

Files changed (1)

File docs/ref/contrib/admin/index.txt

     class AuthorAdmin(admin.ModelAdmin):
         date_hierarchy = 'pub_date'
 
+.. attribute:: ModelAdmin.autocomplete_fields
+
+By default, Django's admin uses a select-box interface (<select>) for fields 
+that are ``ForeignKey`` or ``ManyToMany``.  If you know that your users' 
+browsers will have javascript enabled you can give them autocomplete behavior.
+
+``autocomplete_fields`` is a list of fields you would like to change
+into a smart ``Input`` widget for either a ``ForeignKey`` or ``ManyToManyField``::
+
+    class BookAdmin(admin.ModelAdmin):
+        autocomplete_fields = {
+            'author': { 'fields': ('name',) },
+        }
+
+``autocomplete_fields`` is a dictionary that connects a ``field_name`` to 
+a dictionary of ``field_options``.  The ``field_options`` can have the 
+following keys:
+
+    * ``fields``
+        A tuple of field names used to search for objects associated with 
+        ``field_name``. This key is required.
+
+    * ``label``
+        A subroutine that controls how each choice is displayed in the 
+        list of autocomplete choices.
+
+        Example::
+
+            'label': lambda o: o.name.lower()
+
+    * ``limit``
+        An integer that limits the size of the autocomplete choices displayed.
+
+    * ``show_search``
+        A boolean that controls the rendering of a clickable search icon.  
+        Defaults to `True`. 
+
+    * ``value``
+       A subroutine that controls how a selected item is displayed.
+
+        Example::
+
+            'value': lambda o: o.name
+
 .. attribute:: ModelAdmin.date_hierarchy
 
 Set ``date_hierarchy`` to the name of a ``DateField`` or ``DateTimeField`` in