【发布时间】:2017-08-26 18:37:05
【问题描述】:
我正在使用 django-selectable,我开始紧张了:|
models.py
@python_2_unicode_compatible
class Filing(models.Model):
company = models.CharField(max_length=60, null=True)
ticker = models.CharField(max_length=5, null=True)
number = models.CharField(max_length=15, null=True)
description = models.CharField(max_length=100, null=True)
url = models.CharField(max_length=110, null=True)
created_date = models.DateTimeField(null=True)
def __str__(self):
return self.ticker
lookups.py
from __future__ import unicode_literals
from selectable.base import LookupBase
from selectable.registry import registry
from .models import Filing
class CompanyLookup(LookupBase):
model = Filing
search_fields = ('company__icontains', )
registry.register(CompanyLookup)
所以不要工作:(但是
其他lookups.py
from __future__ import unicode_literals
from selectable.base import LookupBase
from selectable.registry import registry
from .models import Filing
class CompanyLookup(LookupBase):
def get_query(self, request, ticker):
data= Filing.objects.values_list('company',flat=True)
return [x for x in data if x.startswith(ticker)]
registry.register(CompanyLookup)
工作,下拉,但只有“startswith”的属性,我需要“icontains”。也不要使用“istarswith”,也不要使用“contains”:
在我的控制台中:
Request URL:http://127.0.0.1:8000/assets/flash/ZeroClipboard.swf? noCache=1491057317592
Request Method:GET
Status Code:404 Not Found
Remote Address:127.0.0.1:8000
和:
Uncaught ReferenceError: jQuery is not defined
at jquery.dj.selectable.js?v=0.9.0:390
(anonymous) @ jquery.dj.selectable.js?v=0.9.0:390
$(document).ready(function () {
// Patch the django admin JS
if (typeof(djselectableAdminPatch) === "undefined" || djselectableAdminPatch) {
djangoAdminPatches();
}
// Bind existing widgets on document ready
if (typeof(djselectableAutoLoad) === "undefined" || djselectableAutoLoad) {
window.bindSelectables('body');
}
});
})(jQuery || grp.jQuery); <------ this is the line 390
我也不明白为什么,因为在查看源代码
<script type="text/javascript"src="/static/javascript/jquery.dj.selectable.js"></script>
加载正确
如果您能帮助我,请提前感谢您。
【问题讨论】:
标签: django autocomplete jquery-ui-selectable