Monday, November 30, 2020

Ordering objects within a category

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

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/104f2940-8e22-486d-8932-54a544fec8dan%40googlegroups.com.

No comments:

Post a Comment