0

I'm creating a web app that will manage inventory that is placed in boxes. I have installed simple history in Django.

Im trying to write a queryset that returns changes to a boxes contents and orders this data by the date in which this change of content occurred

At the moment I have in my views.py

box_content_history = Box.history.all().order_by('-history_date')

In my HTML:

<table id="table_id" class="display">
<thead>
<tr>
<th>Box</th>
<th>Content Changes</th>
<th>Date of change</th>
</tr>
</thead>
<tbody>
{% for item in box_content_history %}
<tr>
<td>{{ item.box_ref }}</td>
<td>{{ item.box_contents }}</td>
<td>{{ item.history_date }}</td>
</tr>
{% endfor %}
</tbody>
</table>

This displays the box alongside its contents and also the date it was changed. However, its still not ordering the results by this date. Is there something I can do to change this? Thank you very much in advance.

Current table that is not ordering by date (note project/ box refer to the same thing for the purposes of this question)

4

1 回答 1

0

The issue has been solved! The queryset was fine!

I'm using the 'Datatables' package to generate my table in Django and it was this that was not sorting the data correctly. Changing to a normal HTML table sorted the data fine. I will stick to a HTML table for this table I think but will update more if I find out additional information.

于 2018-12-21T00:01:19.917 回答