- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我对regroup有一个问题在 Django .情况是:我有一个views.py的字典,我需要执行以下操作:
Box A_name:
1 section:
1.1 element 1
...
1.n element n
N section:
N.1 element
...
N.m element
Box B_name:
...
html中的代码是:
{% load get_boxfilter %}
{% regroup all_boxes|dictsort:"box_type" by box_type as type %}
<ul>
{% for pos in type %}
<li> Box {{ pos.grouper|get_boxfilter }}
<ul>
{% for item in pos.list %}
<li> element {{ item.name }} section {{ item.section }}</li>
{% endfor %}
</ul>
</li>
{% endfor %}
</ul>
获取框过滤器:
#!/usr/bin/python
# -*- coding: utf-8 -*-
from django import template
register = template.Library()
@register.filter(name='get_groupfilter')
def get_boxfilter(value):
gb_list = [u"NULL", u"A_name", u"B_name", u"N_name" ]
return gb_list[int(value)]
它通过盒子名称重新组合:
Box A_name:
1. element 1 section 1
2. element 2 section 2
3. element 3 section 1
Box B_name:
...
但是如何按“部分”(int 值)分组?
Box A_name:
1 section:
1.1 element 1
1.2 element 3
2 section:
2.1 element 2
谢谢
最佳答案
为什么不直接按部分重新分组?
{% load get_boxfilter %}
{% regroup all_boxes by section as type %}
<ul>
{% for pos in type %}
<li> Box {{ pos.type|get_boxfilter }}
<ol style="list-style-type: decimal">
<li>{{ pos.grouper }}</li>
<ol style="list-style-type: decimal">
{% for item in pos.list %}
<li> element {{ item.name }}</li>
{% endfor %}
</ol>
</ol>
</li>
{% endfor %}
</ul>
关于python - Django 重组列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13938384/
目录 一、状态变化 1.1 状态变化是什么 1.2 mutableStateListOf 和 mutableStateMapOf 二、重组的
这是我的真实数据列表的示例列表: df setNames(nm) } fun3 Unit: microseconds #> expr min lq me
在 clojure 中,我可以像这样解构 map : (let [{:keys [key1 key2]} {:key1 1 :key2 2}] ...) 这类似于 CoffeeScript 的方法
这个问题在这里已经有了答案: Re-Structuring a JSON (2 个答案) 关闭 9 年前。 我需要使用 Javascript/Jquery 将我的 JSON 重新组织成新的结构,但我
我有一个具有以下结构的表,列是出发地、目的地、旅行时间和出发时间。主键是出发地、目的地和出发时间的组合。有没有什么方法可以重新构造它,以便行中没有太多的起点和目的地重复? 最佳答案 “出发地和目的地太
需要将 JSON 重组为 Python 中的新结构。 例如: { 'a' : 1, 'b' : 1, 'd' : {'d1' : '1', 'd2' : 2}, 'm' : [
我正在努力了解重组的工作原理。虽然我理解它的基本概念,但我在使用 withProps 函数时遇到了问题。如果我尝试使用它来装饰带有附加 Prop 的组件的每个子组件,它根本无法工作。我所做的是: co
假设我有一个数据框列表。每个数据框都有这样的列: lists$a company, x, y ,z lists$b company, x, y, z lists$c company, x, y, z
好吧,我有这个数组 $city : [2] => Array ( [0] => Array ( [0] => fr
工作中的 subversion 存储库是在没有对其结构进行太多规划的情况下建立的。目前没有明确的标签、主干或分支配置,尽管通过使用 subclipse:tags 存在一些标签元数据 目前存储库的格式为
我有一个具有以下文件夹结构的 Git 存储库: allprojectfiles --otherfolders --source ----projectname ------projectname --
我有一个像这样的 git repo 结构- main-repo -file1 -file2 我想把它转换成类似的东西- main-repo -javascript -fil
我有一个像这样的 git repo 结构- main-repo -file1 -file2 我想把它转换成类似的东西- main-repo -javascript -fil
有人建议我从类结构(定义我自己的类)转移到 pandas DataFrame 领域,因为我设想对我的数据进行许多操作。 此时我有一个如下所示的数据框: ID Name Recordin
我想重构我的 pandas 数据框,其中 h1、h2 等是与小时相关的值。目前看起来像: h1 h2 h3 h4 h5 h6 h7 h8 h9
我在 postgresql 上使用查询返回这样的结果。 schedule | day | subject | grade | ========================
我有一个这样组织的数据框... **Name** | **Mealtime** | **Food** John | 8:00 am | cereal John | 1:00 pm | salad
我有基本的脚本知识,但我不知道如何解决这个问题。我正在尝试将银行自动生成的 CSV 文件转换为 YNAB(您需要预算)可以理解的格式。 YNAB 格式(所需的 csv 文件格式) Date,Payee
我正在重组我的 meteor 应用程序,突然每个逻辑(JS 脚本)与初始文件分离的 View (html 模板)都停止工作。 最初我的项目看起来像这样 -project -.meteor
我试图让 children 不影响导航栏,并像下拉菜单一样显示。 当前示例位于:dev4you.byethost15.com 函数应该如下: 用户将鼠标悬停在父项上 子项显示在类似列表、Underne
我是一名优秀的程序员,十分优秀!