1

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

1 Answer 1

1

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>
Sign up to request clarification or add additional context in comments.

7 Comments

Is it possible to display a first line as field name then objects ?
Yeah I found this HTML command ;) If I want to display array lines, it's with javascript ?
I do not understand what you want to say as "array lines", can you give me an example?
I mean drawing an array. Draw all array contours ?
You can use the forloop.counter inside {%
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.