Ordering objects within a category

11 views
Skip to first unread message

andrew.f...@gmail.com

unread,
Nov 30, 2020, 5:53:22 PM11/30/20
to Django users
Hi All.

I’m trying to solve an annoying issue with ordering.  

I have a site that displays lists of objects.  These objects also belong to categories.

The site defaults to show the objects from all the categories.  I can order these objects based on a model.  However, if I select a category, I cannot order the displayed objects within that category.  

Here is the html snippet that I use to order the objects when all categories are displayed.  It works well... just not for objects in specific categories.

<!-- sort html snippet -->
<div class="iconsets-sort">Ordered by
{% if ordering == 'title' %}
<span>Title</span>
{% elif ordering == 'filename' %}
<span>Filename</span>
{% elif ordering == '-author' %}
<span>Author</span>
{% elif ordering == 'created' %}
<span>Date Created</span>
{% elif ordering == '-updated' %}
<span>Last Updated</span>
{% elif ordering == '-status' %}
<span>Status</span>
{% elif ordering == 'iteration_pending' %}
<span>Pending</span>
{% elif ordering == 'iteration_approved' %}
<span>Approved</span>
{% elif ordering == '-notes' %}
<span>Iconsets with Notes</span>
{% endif %}
<img class="sort-down-arrow-2" src="{% static 'idm/images/main-content-icons/down-arrow-2.svg' %}">
<ul>
<li class="sort"><a href="?ordering=title"> Title</a></li>
<li class="sort"><a href="?ordering=-author"> Author</a></li>
<li class="sort"><a href="?ordering=filename"> Filename</a></li>
<li class="sort"><a href="?ordering=created"> Create Date</a></li>
<li class="sort"><a href="?ordering=-updated"> Last Updated</a></li>
<li class="sort"><a href="?ordering=-status" > Status</a></li>
<li class="sort"><a href="?ordering=iteration_pending"> Pending</a></li>
<li class="sort"><a href="?ordering=iteration_approved"> Approved</a></li>
<li class="sort"><a href="?ordering=-notes"> Notes</a></li>
</ul>
</div>

I’m not sure what code needs to be shown so if anyone can help let me know and I will share what is needed.

Regards and I hope everyone is well.
-Andrew
Reply all
Reply to author
Forward
0 new messages