0
django-selectable을 사용하고 있습니다.Django 선택 가능 자동 완성 취소하지 않음
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)
작품 방울을 작동 :(하지만
하지 않습니다 아래로,하지만 attr에서만 "startswith"의 ibutes와 나는 "icontains"을 필요로한다. 또한, 어느 쪽도 "가없는"일 "istarswith"하지 않습니다
을 내 콘솔에서 :
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>
는
제대로로드도와 주시면 미리 감사드립니다.
완벽하게 작동합니다! :) 그리고 매우 우아한 솔루션 .. 정말 고마워요 .. – pepew