我的开发环境正在运行python 2.7.1,并且生产正在运行2.7.6
以下代码在开发时运行良好,但在生产时不会触发new_city字段的自动完成:
Admin.py
class LocationAdminForm(autocomplete_light.ModelForm):
class Media:
js = ('dependant_autocomplete.js',)
class Meta:
model = Location
fields = ['name', 'instagram_id', 'country', 'new_country', 'city', 'new_city']
class LocationAdmin(admin.ModelAdmin):
list_display = ['name', 'country', 'city', 'new_country', 'new_city']
search_fields = ['name', 'new_country', 'new_city']
list_editable = []
list_filter = ['new_city', 'new_country']
form = LocationAdminForm
autocomplete-registry.py
class AutocompleteCity(autocomplete_light.AutocompleteModelBase):
autocomplete_js_attributes={'placeholder': 'city name ..'}
def choices_for_request(self):
q = self.request.GET.get('q', '')
country_id = self.request.GET.get('country_id', None)
choices = self.choices.all()
if q:
choices = choices.filter(name__icontains=q)
if country_id:
choices = choices.filter(country_id=country_id, name__icontains=q)
return self.order_choices(choices)[0:self.limit_choices]
autocomplete_light.register(Location, AutocompleteCity)
autocomplete_light.register(City, search_fields=('name'),
autocomplete_js_attributes={'placeholder': 'city name ..'})
有什么理由可以解决这个问题或者我如何解决问题?
答案 0 :(得分:0)
在查看autocomplete-light文档后,我在LocationAdminForm中缺少以下内容:
widgets = autocomplete_light.get_widgets_dict(Location)