Display table data django

141 Views Asked by At

I want to display data from a table in a table; to retrieve the object I used the foreign key to retrieve the object (person depending on the project) I have two tables: 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
...

in the views : in the display function :

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 have two problems:

  • I can not display the data on my chart
  • How to increment the i 1
1

There are 1 best solutions below

0
On

You'll need to provide more information about your view function to fix the first problem (how and what are you returning from this function? Note also your typo in projet=project), but you get the loop counter with forloop.counter:

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

(or forloop.counter0 if you want zero-based indexes).