javascript - Django: django-autocomplete-light does not work properly -
i'm using django-autocomplete-light
in django 1.8. don't know how use in forms.py
. instead of autocomplete field see select field. followed instructions here.
in models.py
have:
class icd_10(models.model): id = models.integerfield(unique=true,primary_key=true,null=false,blank=false) icd_10_desc = models.charfield('icd-10 description',max_length=80,null=true,blank=true) icd_10_code = models.charfield('icd-10 code',max_length=10,null=true,blank=true) def __str__(self): return str(self.icd_10_desc) class diagnosis(models.model): diagnosis_option = models.manytomanyfield(diagnosisoption) record_of_genotype = models.charfield(max_length=45,null=true,blank=true) icd_10_desc = models.manytomanyfield(icd_10) patient = models.foreignkey(demographic) def __str__(self): return str(self.patient)
in settings.py
have:
installed_apps = ( 'dal', 'dal_select2', 'django.contrib.admin', ... )
in views.py
have:
class icdtenautocomplete(autocomplete.select2querysetview): def get_queryset(self): #don't forget filter out results depending on visitor ! if not self.request.user.is_authenticated(): return icd_10.objects.none() qs = icd_10.objects.all() if self.q: qs = qs.filter(icd_10_desc__istartswith=self.q) return qs
in urls.py
have:
url(r'^icd10-autocomplete/$','ereg.views.icdtenautocomplete',name='icd10-autocomplete'),
and in forms.py
have:
class diagnosisform(forms.modelform): def __init__(self, *args, **kwargs): super(diagnosisform, self).__init__(*args, **kwargs) self.helper.layout = layout( fieldset ( # 'patient', '<b>diagnosis information</b>', 'diagnosis_option', 'icd_10_desc', ), formactions( submit('submit', "save changes"), submit('cancel',"cancel") ), ) self.helper.form_tag = false self.helper.form_show_labels = true class meta: model = diagnosis exclude = ['patient', 'author'] list_display = ('patient', 'pub_date', 'author') widgets={'icd10_desc' : autocomplete.modelselect2multiple(url='icd10-autocomplete')}
when run directly browser works properly. get
{"pagination": {"more": false}, "results": [{"text": "thalassemia", "id": 8}, {"text": "thalassemia trait", "id": 12}, {"text": "thalassemia, unspecified", "id": 15}]}
so, miss proper javascript?
i found solution! had include code below in template:
{% block footer %} <script type="text/javascript" src="http://dal-yourlabs.rhcloud.com/static/collected/admin/js/vendor/jquery/jquery.js"></script> {{ frm.media }} {% endblock %}
and code below in base.html template inherits data.
<link src="/static/collected/autocomplete_light/vendor/select2/dist/css/select2.css" type="text/css" media="all" rel="stylesheet" /> <link src="/static/collected/autocomplete_light/select2.css" type="text/css" media="all" rel="stylesheet" /> <script type="text/javascript" src="/static/collected/autocomplete_light/autocomplete.init.js"></script> <script type="text/javascript" src="/static/collected/autocomplete_light/select2.js"></script>
Comments
Post a Comment