Django FilteredSelectMultiple widget更改工具提示标题

时间:2016-08-07 09:13:00

标签: django django-models django-forms django-templates widget

我正在使用Django 1.9以下内容:

models.py:

class LocationPoint(models.Model):
    title = models.CharField(max_length=30)
    radius = models.FloatField(null=True, blank=True)
    point = models.PointField(srid=4326, null=True, blank=True)
    objects = models.GeoManager()

    def __unicode__(self):
        return self.title

forms.py:

from django.contrib.admin.widgets import FilteredSelectMultiple
from api.models import *

class PopulationConstraintsForm(forms.ModelForm):
    location_point = forms.ModelMultipleChoiceField(
        queryset=LocationPoint.objects.all(),
        widget=FilteredSelectMultiple("location point", is_stacked=False)
    )

和template.html

<div class="row">
    {{ form.location_point }}
</div>

结果是: enter image description here

当我将鼠标悬停在位置点模型中的对象上时,如何更改显示的工具提示标题(在工具提示显示的示例中&#34; TelAviv&#34;)?

小部件自动生成的html。

1 个答案:

答案 0 :(得分:0)

我设法通过使用F12的整个div输出进行一些改动:

<select multiple="multiple" class="filtered" id="id_location_point_from" name="location_point_old">
    {% for c in  form.fields.location_point.queryset%}
        <option value="{{ c.id }}" title="My Title">{{  c.title }}</option>
    {% endfor %}
</select>
相关问题