1

I want to design a table can compare with each other by year.

my data like this:

book Data Image

# views.py
def bybook(request, bookName='A-Book'):
    bookdata = models.bookdb.objects.filter(bookName=bookName).order_by('Year', 'point')
    return render(request, 'book.html', locals())

I hope result want:

enter image description here

What i have tryed django templates regroup https://docs.djangoproject.com/en/2.0/ref/templates/builtins/#regroup

but can't achieve my require.

1
  • Post what you have tried please. Commented Aug 2, 2018 at 5:16

1 Answer 1

2

In the django template

#first we create the header of the table with the years
<tr class="first-table-row">
        # leave it blank so the first column is empty
        <th></th>
        #loop trough the items
        {% for i in bookdata %} 
           <th>{{i.year}}</th>
        {% endfor %}
</tr>
#loop trough the items again
{% for i in bookdata %}
       <td>{{i.point}}</td>
        # I don't know how your object is structured man please submit it so I can continue 
{% endfor %}
Sign up to request clarification or add additional context in comments.

Comments

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.