过滤django queryset的字母模板标记
alphabetic-simple的Python项目详细描述
用于构建字母索引的django模板标记
链接到存储库:https://github.com/Arpaso/alphabetic-simple
构建alPabetic索引,以便在按firstletter排序的集合中导航。 支持英语和俄语字母组。
用法
view.py:
from django.views.generic.list_detail import object_list from alphabetic.utils import alphabetic_setup from .models import MyModel def myview(request): ... queryset = MyModel.objects.all() return object_list(request, alphabetic_setup(request, queryset, 'last_name'), template_name=template)
template.html:
{% show_alphabetic_filter %}
字母设置(请求,queryset,'last_name')-按字母顺序返回排序的queryset 属性名,例如last_name或您指定的模型的任何属性。
show_alphabetic_filter-模板标记显示模板中可单击的字母表。
单击该字母将生成对当前url的get请求,并带有尾部?第一个字母=x, 其中x是单击的字母。
arpaso公司开发团队撰写:http://arpaso.com