Try something like this: 

    'customer': autocomplete_light.ChoiceWidget('CustomerAutocomplete')   

http://django-autocomplete-light.readthedocs.org/en/latest/tutorial.html#override-a-default-relation-select-in-modelform-meta-widgets

On Thursday, February 14, 2013 6:22:00 PM UTC+1, Derek wrote:
>
> I am trying to make use of the autocomplete-light app for Django (
> https://github.com/yourlabs/django-autocomplete-light/).  When I use it 
> in the admin with the format:
>     form = autocomplete_light.modelform_factory(Foo)
> then it works just fine.  However, when I want to use it in an existing 
> admin form, then it simply does not work (i.e. no error is reported, the 
> look-up list remains the normal one).
>
> The following example shows the type of approach I have taken.  All the 
> files are within the app directory.
>
> I'm sure I am missing something simple; and any help is appreciated.
>
> Thanks
> Derek
>
> CODE SAMPLE; the Meeting object has a look-up to Customer, which is a 
> Person object
>
> #... in autocomplete_light_registry.py
>
> import autocomplete_light
> from models import Person
>
> class CustomerAutocomplete(autocomplete_light.AutocompleteModelBase):
>     search_fields=('name', 'nickname', )
>     autocomplete_js_attributes={'placeholder': 'name/nickname...'}
>
> autocomplete_light.register(Person, CustomerAutocomplete)
>
> #... in admin.py
>  
> import autocomplete_light
> import autocomplete_light_registry
> from models import Meeting
>  
> class MeetingAdminForm(forms.ModelForm):
>
>     class Meta:
>         model = Meeting
>         widget = {
>             'customer': autocomplete_light.ChoiceWidget(
>                 autocomplete_light_registry.CustomerAutocomplete)        
>         }
>
>     def __init__(self, *args, **kwargs):
>         # other code here...
>         
>     #other methods here...
>
> class MeetingAdmin(admin.ModelAdmin):
>     form = MeetingAdminForm
>     # other code here...
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to