Essex
Essex

Reputation: 6128

Display QuerySet result as Array

I'm asking a question about my HTML template. I displayed results from some QuerySet with Django and I would like to modify the display user aspect.

I don't know if I can make this kind of things with Django or if JavaScript lets to make that.

I have an HTML template :

<h2 align="center"> Affichage de toutes les fiches individuelles </align> </h2>

<br></br>

{% block content %}

<h4> Récapitulatif des 10 dernières fiches individuelles créées: </h4>
<ul>
{% for item in identity %}
   <li>{{ item }}</li>
{% endfor %}
</ul>

<h4> Récapitulatif des 10 dernières fiches individuelles créées habitant en France: </h4>
<ul>
{% for item in identity_France %}
   <li>{{ item }}</li>
{% endfor %}
</ul>

{% endblock %}

From this view :

def Consultation(request) :

    identity = Identity.objects.all().order_by("-id")[:10] #Les 10 dernières fiches créées
    identity_France = Identity.objects.filter(country='64').order_by("-id")[:10] #Les 10 dernières fiches où la personne habite en France

    context = {
        "identity" : identity,
        "identity_France" : identity_France,
    }
    return render(request, 'resume.html', context)

Is it possible to display the result as an array ? With column, tags for each column etc ... ?

Something like that :

enter image description here

Thank you !

EDIT :

I found that JQuery makes that : JQuery Array

Upvotes: 1

Views: 100

Answers (1)

Evaldo Bratti
Evaldo Bratti

Reputation: 7668

You can do whatever you want inside {% for %} {% endfor %} template tags. like, you could put your objects inside a table

<table>
  <thead>
     <tr>
       <th>Field 1 Name</th>
       <th>Field 2 Name</th>
     </tr>
   </thead>
   <tbody>
   {% for item in identity_France %}
      <tr>
        <td>{{ item.field1 }}</td>
        <td>{{ item.field2 }}</td>
      <tr>
   {% endfor %}
   <tbody>
</table>

Upvotes: 1

Related Questions