#14370: Adding support for Autocomplete in contrib.admin
----------------------------------+-----------------------------------------
 Reporter:  tyrion                |       Owner:  nobody    
   Status:  new                   |   Milestone:            
Component:  django.contrib.admin  |     Version:  1.2       
 Keywords:  autocomplete          |       Stage:  Unreviewed
Has_patch:  0                     |  
----------------------------------+-----------------------------------------
 I've tried to implement Autocomplete for contrib.admin using jQuery UI
 Autocomplete.[[BR]]
 Here's the code: http://bitbucket.org/tyrion/django [[BR]]
 Here's a live demo: http://djangoac.tyrion.mx/admin/ (login with
 test/test).
 (It supports both ForeignKey and ManyToMany).

 I don't know if I should attach the complete patch here. It's kinda big (I
 included jquery-ui), however you can see it online at
 http://bitbucket.org/tyrion/django/changeset/04488ec05e92 ).

 Now it's implemented using an "autocomplete_fields" attribute which is a
 dict (field:related_fields):
 {{{
 #!python
 class MyModelAdmin(admin.ModelAdmin):
     autocomplete_fields = {'user': ('username', 'email')}

 }}}

 But because I've been asked:
 {{{
 <jezdez> tyrion-mx: what about making the autocomplete_fields a dict of
 dicts, to be able to specify additional options for the autocompletion,
 e.g. number of search results or a custom label function?
 }}}
 I've written this patch (for my code) http://dpaste.com/hold/251220/
 that let's you control the "value" (what is displayed in the input),
 "label" (what is displayed in the dropdown) and "limit" (max number of
 results) properties.

 With it a modeladmin could look something like this:
 {{{
 #!python
 class DummyAdmin(admin.ModelAdmin):
     autocomplete_fields = dict(
         user1 = dict(
             fields = ('username', 'email'),
             value = 'username',
             limit = 10,
         ),
         friends = dict(
             fields = ('username', 'email'),
             label = u'%(first_name)s %(last_name)s',
             value = 'email',
         ),
     )
 }}}

 In that case "value" and "label" can be either a function, a fieldname or
 a string like `u'%(username)s "%(email)s"'`.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/14370>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to