如何通过django-autocomplete-light使用django-haystack自动完成功能

时间:2016-05-21 05:34:48

标签: django django-haystack django-autocomplete-light

我正在尝试通过django admin中的django-autocomplete-light实现django-haystack自动完成功能。我使用的是django = 1.9.6,django-haystack-2.4.1,django-autocomplete-light = 3.1.5。我浏览了django-autocomplete-light教程中给出的示例,并且能够成功实现它。对于外键字段,它构建查询集并返回对象。

现在为了从haystack获取结果,我需要更改get_queryset方法以从haystack返回查询集。我相信这可以通过实现 using System.IO; using System; using System.Collections.Generic; using System.Linq; class Program { static void Main() { var values = new List<string>{"a","b","c","d","e","a","b","c","d","e","a","b","c","d","e"}; var order = new List<string>{"a","b","c","d","e"}; var sortedList = SortByList(values, order); foreach(var i in sortedList) { Console.WriteLine(i); } } public static List<string> SortByList(List<string> values, List<string> order){ return values.OrderBy(x => order.IndexOf(x)).ToList(); } } 。我正朝着正确的方向前进吗?任何帮助都非常感谢。感谢。

0 个答案:

没有答案