python - django 用重复的 nametuple 重组
问题描述
我在 django 模板中有重新组合的代码,如下所示:
{% regroup clients by title.0 as clients_list %}
{% for client in clients_list %}
{{ client.grouper }}
{% for item in client.list %}
{% if item.client_link %}
<a href="{{ item.client_link }}">{{ item.title }}</a>
{% else %}
{{ item.title }}
{% endif %}
{% endfor %}
{% endfor %}
有时我的结果中有相同字母的重复名称元组,例如 - 'd':
GroupedResult(grouper='d', list=[<Client: decompany_1>]) GroupedResult(grouper='d', list=[<Client: decompany_2>])
所以结果我有两个带有字母“d”的标题
有人知道,如何避免这种情况?
编辑 视图.py
class ClientsListView(ListView):
model = Client
template_name = 'clients/clients_list.html'
context_object_name = 'clients'
解决方案
推荐阅读
- c# - 如何计算数组中的“平均值”、“最高”值和“最低”值?C#
- python - 在 cv.normalize() 之后,结果的像素为 0 ,为什么?
- sed - 在文件中追加字符串的命令
- android - isInBitmapMemoryCache 为不同的 url 返回 true
- javascript - 如何在 nodejs 上运行时将 Javascript 文件添加到 HTML
- javascript - 在页面加载时,我需要反弹高度减小的图像。我能够反弹图像但高度相同
- c# - 基于简单条件的 ASPNetCore wepApi 身份验证
- java - 是否有任何库可以让我们在 recyclerview 中获得选取框效果(例如 hotstar vip 页面滚动图像)?
- c# - 如何为具有不同属性的嵌套类定义映射?
- angular - ngx-chips 自动完成返回值以及显示字符串