【问题标题】:Display table data django显示表数据django
【发布时间】:2017-03-14 02:31:48
【问题描述】:

我想在表格中显示表格中的数据;检索对象我使用外键检索对象(取决于项目的人) 我有两个表:person 和 project。

    class person (models.Model)
    project =models.ForeignKey('plat_project.Project', blank=True,related_name='project')
    pourcentage = models.IntegerField()
    sum = models.IntegerField()

    class project
...

在视图中: 在显示功能中:

PersonneProject=PersonneProjet.objects.all(projet=project)
        response['Listeperson']=PersonneProject


And the template :
{% for p in Listeperson %}
        <tr>
        <td style="text-align:center">{{ i }} </td>
        <td style="text-align:center">{{ p.pourcentage}}% </td>
        <td style="text-align:center">{{ p.sum }}€ </td>
         </tr>
  {% endfor %}

我有两个问题:

  • 我无法在图表上显示数据
  • 如何增加 i 1

【问题讨论】:

    标签: django html-table displayobject


    【解决方案1】:

    您需要提供有关您的视图函数的更多信息以解决第一个问题(您如何以及从该函数返回什么?还要注意您在projet=project 中的拼写错误),但您会获得带有@987654322 的循环计数器@:

    <td style="text-align:center">{{ forloop.counter }} </td>
    

    (或forloop.counter0,如果您想要从零开始的索引)。

    【讨论】:

      猜你喜欢
      • 2015-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-09
      • 2011-07-10
      • 2019-06-06
      • 1970-01-01
      相关资源
      最近更新 更多