0

Newbee here. I'm using django-autocomplete-light for my foreign field key in django admin. It's working great. But once I selected an item the plus sign is thrown below the item.

Is there a way for the plus sign to stay in line with the selected item to save space?

EDIT for clarity - I'm using django grappelli. enter image description here

Thank you django-autocomplete-light author, jpic for explaining how to override the template and css. Good thing I can paste image now.

In the image above I have two autocomplete, Public Telecom Entity (PTE) and Antenna. The customized form is using

class Meta: widgets = autocomplete_light.get_widgets_dict(Equipment) 

PTE is defined in the form as

carrier = forms.ModelChoiceField(Carrier.objects.all(), 
                 label="Public Telecom Entity",    
                 widget=autocomplete_light.ChoiceWidget('CarrierAutocomplete', 
                 attrs='style':'width:520px;',})) 

But I did not defined Antenna. I assume, this field will be using the Meta widget.

4

1 回答 1

1

有没有办法让加号与所选项目保持一致以节省空间?

加号对我来说似乎没问题:

在此处输入图像描述

虽然没有按钮可以推动加号与所选项目保持一致以节省空间(我什至不清楚),但您可以根据自己的喜好修改小部件的设计。这就是我将在此答案中详细说明的内容。

覆盖小部件模板

您可以覆盖模板autocomplete_light/widget.html

为此,请复制/path/to/autocomplete_light/templates/autocomplete_light/widget.htmlautocomplete_light您的其中一个TEMPLATE_DIRS. 例如:

mkdir ~/your_project/templates/autocomplete_light
cp ~/env/lib/python/site-packages/autocomplete_light/templates/autocomplete_light/widget.html ~/your_project/templates/autocomplete_light

重新启动服务器,您就可以安全地编辑~/your_project/templates/autocomplete_light/widget.html.

覆盖样式表

样式表也是如此。要破解它,您所要做的就是将其复制autocomplete_light/static/autocomplete_light/style.css到您的STATICFILES_DIRS. 如果您仍然不确定django staticfiles 是如何工作的,您可能需要阅读Surviving staticfiles。例如:

mkdir ~/your_project/static/autocomplete_light
cp ~/env/lib/python/site-packages/autocomplete_light/static/autocomplete_light/style.css ~/your_project/static/autocomplete_light

重新启动您的开发服务器,您可以根据自己的喜好安全地进行修改~/your_project/static/autocomplete_light/style.css

如果你认为你有更好的方法

如果您认为您对 autocomplete-light v1 提供的默认小部件有更好的想法,请随时在github上打开拉取请求。

于 2013-12-10T15:30:17.067 回答