@staticmethod # known case of __new__ def__new__(*args, **kwargs):# real signature unknown """ Create and return a new object. See help(type) for accurate signature. """ pass
关于 groupby 的使用说明:
1 2 3 4 5 6
itertools.groupby @overload def __new__(cls, iterable: Iterable[_T1], key: None = ...) -> groupby[_T1, _T1] Create and return a new object. See help(type) for accurate signature.
# views.py deftodo_list(request): param = request.GET.get('status') if param: todos = Todo.objects.filter(is_deleted=False).filter(status__exact=int(param)) else: todos = Todo.objects.filter(is_deleted=False) todos_sorted = sorted(todos, key=lambda x: x.group.name) return render(request, 'todo/list.html', {'todos': todos_sorted})
# todo/list.html ... ... {% regroup todos by group as group_list %} {% for group in group_list %} {{ group.grouper }} {% for todo in group.list %} {{ todo.name }} {% endfor %} {% endfor %} ... ...