django-address
django-address copied to clipboard
Error when using together with Django autocomplete fields in admin
I'm registering MyModel in the admin:
@admin.register(MyModel)
class MyModel(admin.ModelAdmin):
search_fields = ['field_1',]
filter_horizontal = ['phone_fk', 'email_fk',]
formfield_overrides = {AddressField: {"widget": AddressWidget(attrs={"style": "width: 400px;"})}}
autocomplete_fields = ['parent', ]
When autocomplete_fields is set, following error occurs:
jquery.js:4050 jQuery.Deferred exception: self.geocomplete is not a function TypeError: self.geocomplete is not a function
at HTMLInputElement.
My guess is, the autocomplete field loads it's on jQuery for select2, and this somehow interferes...
Any idea for a workaround?
@spechtx Thanks for pointing this out. I am running into the same issue. Have you found a workaround in your case?
There's a warning about autocomplete_fields
implying custom widgets of their own in the django docs here: https://docs.djangoproject.com/en/4.2/ref/contrib/admin/#django.contrib.admin.ModelAdmin.formfield_overrides
I was not able to find a link with the issue mentioned here. My “workaround” is not to use autocomplete_fields
and AddressWidget on the same page.
IMHO, a solution here lies in the deprecation of the use of jquery
in this library, as described in https://github.com/furious-luke/django-address/issues/139.