It’s very likely that your data is in a different format (csv or pipe delimited), like this:
12
Rxcui|ShortName|IsBrand1234|Advil|1
So we need to import that data. A database copy command (postgres, mysql, sqlite) will not deal very nicely with our Django auto-incrementing keys, so we need to add the data using a django view, such as this:
12345678
importcsvfrommyproject.main.modelsimportDrugdefload_drugs(file_path):"this loads drugs from pipe delimited file with headers"reader=csv.DictReader(open(file_path))forrowinreader:drug=Drug(rxcui=row['Rxcui'],short_name=row['Short Name'],is_brand=row['Is Brand'])drug.save()
Cool. Now we need to actually write the template where the search is. We’ll use jQuery Autocomplete because that’s what the cool kids do. Let’s first import jQuery and jQueryUI in our base template:
Note that jQuery autocomplete sends the query as “term” and it expects back three fields: id, label, and value. It will use those to display the label and then the value to autocomplete each drug.
We now have an AJAX jQuery Autocomplete Search with Django. Hope this helps.