python - django autocomplete light on admin: how does it work? -
i'm trying make searcheable customer foreigkey on model on admin.
i has installed django autocomplete light, can`t see works.
i'm trying this.
admin.py
import autocomplete_light class redadminform(forms.modelform): class meta: model = red widget = {'customer': autocomplete_light.choicewidget('customerautocomplete')} class redadmin(admin.modeladmin): #form = redadminform list_display = ("id", "customer","sponsor") list_per_page = 10 search_fields=['customer__username', 'sponsor__username'] #raw_id_fields = ('customer','sponsor',) form = autocomplete_light.modelform_factory(red) admin.site.register(red, redadmin)
i have css , js static files of module, has installed , put on installed apps.
autocomplete_light_registry.py
import autocomplete_light django.contrib.auth.models import user autocomplete_light.register(user)
show error on ajax request:
fielderror @ /autocomplete/userautocomplete/ cannot resolve keyword u'name' field. choices are:
for moment, autocomplete-light doesn't reuse modeladmin's search_fields. there's open pr that.
try registering search_fields ie.:
registry.register(user, search_fields=['username', 'email'])
Comments
Post a Comment