django-selectable:没有下降

时间:2013-01-29 20:51:13

标签: django autocomplete

我正在尝试使用django-selectable http://django-selectable.readthedocs.org/en/version-0.6.2/quick-start.html

我已经按照我能正确说明的方式设置了一切(见打击)。在FireBug中,正在进行请求并返回有效的JSON。一切正常,但没有显示结果。我已经包含了CSS。

我没有看到下拉的任何原因?

FF出现此错误:

TypeError: this.menu is undefined
[Break On This Error]   

if ( this.menu.element.is( ":visible" ) ) {

models.py

class Event(models.Model):
    event_id = models.IntegerField(primary_key=True)
    name = models.CharField(max_length=80,blank=False)
    date = models.DateField()
    start = models.TimeField()
    end = models.TimeField()

    category = models.ForeignKey(Category)
    city = models.ForeignKey(City)
    user = models.ForeignKey(User)

    def __unicode__(self):
        return self.name

lookup.py

from selectable.base import ModelLookup
from selectable.registry import registry

from events.models import Event


class EventLookup(ModelLookup):
    model = Event
    search_field = 'city__icontains'
    filters = {'active': True, }

    def get_item_value(self, item):
        # Display for currently selected item
        return item.name

    def get_item_label(self, item):

        return u"%s (%s)" % (item.name)

registry.register(EventLookup)

forms.py

from django import forms
from django.forms import ModelForm
from events.models import Event
import selectable.forms as selectable
from events.lookups import EventLookup


class EventForm(ModelForm):
    autocomplete = forms.CharField(
        label='Type the name of a fruit (AutoCompleteWidget)',
        widget=selectable.AutoCompleteWidget(EventLookup),
        required=False,
    )

    class Meta:
        model = Event

urls.py

(r'^selectable/', include('selectable.urls')),

template.html

  **the following is loaded in correctly...**
    jquery-1.9.0.js
    jquery-ui-1.10.0.custom.min.css
    jquery.ui.core.js
    jquery.ui.widget.js
    jquery.ui.datepicker.js
    jquery.ui.autocomplete.js


     {{ form.media.css }} 
     {{ form.media.js }} 
     {{ form }}

1 个答案:

答案 0 :(得分:4)

看起来是正确的,我认为:

1)您没有按正确的顺序包含js文件

2)你没有正确加载它们。

将以下内容添加到您的头部并删除您的链接,看看它是否有效......

<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/
1.8.13/themes/ui-lightness/jquery-ui.css" type="text/css" />
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/
jquery/1.4.4/jquery.min.js"></script>
{{ form.media.js }}
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/
jqueryui/1.8.13/jquery-ui.min.js"></script>
{{ form.media.css }}