django-autocomplete-light django 1.8 custom modelform for admin -
i want add autocomplete onetoone field django-admin
class banner(models.model): product = models.onetoonefield(product, null=true) class banneradmin(admin.modeladmin): form = bannerform
stucked on https://django-autocomplete-light.readthedocs.org/en/stable-2.x.x/tutorial.html?highlight=tutorial#tutorial - anything changed after following steps (same list widget 'product' ...):
what have done:
- installed :d
- added 'autocomplete_light', installed_apps
- overrided admin/base_site.html (using custom loader)
- url(r'^autocomplete/', include('autocomplete_light.urls')), urlpatterns
- autocomplete_light_registry.py model banner , search_fields=['product'],
- updated modelform:
class bannerform(autocomplete_light.modelform): class meta: model = banner fields = ['product', 'priority', 'image'] autocomplete_fields = ['product']
what i've missed?
following resolved problem:
- before admin in installed_apps
installed_apps = ( 'autocomplete_light', 'django.contrib.admin', )
- autocomplete_light_registry.py
class bannerautocomplete(autocomplete_light.autocompletemodelbase): model = banner search_fields = ('name',) # banner_obj.product.name choices = product.objects.all() limit_choices = 20 autocomplete_light.register( bannerautocomplete, attrs={ 'placeholder': _(u'имя товара'), 'data-autocomplete-minimum-characters': 1, }, )
- manually select autocomplete related field in form:
class bannerform(autocomplete_light.modelform): class meta: model = banner fields = ['product', 'priority', 'image'] autocomplete_names = {'product': 'bannerautocomplete'}
Comments
Post a Comment