gpt4 book ai didi

Django 可选 : no drop down

转载 作者:行者123 更新时间:2023-12-05 00:58:11 25 4
gpt4 key购买 nike

我正在尝试使用 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" ) ) {

模型.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')),

模板.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)您没有以正确的顺序包含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 }}

关于Django 可选 : no drop down,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14592000/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com