Explicit secondary ordering of categories

This commit is contained in:
Raphael Michel
2015-02-11 18:41:36 +01:00
parent 270a359e2e
commit a026d838f7
2 changed files with 4 additions and 3 deletions
+1 -1
View File
@@ -429,7 +429,7 @@ class ItemCategory(Versionable):
class Meta:
verbose_name = _("Item category")
verbose_name_plural = _("Item categories")
ordering = ('position',)
ordering = ('position', 'id')
def __str__(self):
return self.name
+3 -2
View File
@@ -28,7 +28,8 @@ class EventIndex(EventViewMixin, TemplateView):
# Regroup those by category
context['items_by_category'] = sorted([
# a group is a tuple of a category and a list of items
(cat, [i for i in items if i.category_id == cat.identity])
for cat in set([i.category for i in items])
], key=lambda group: group[0].position)
for cat in set([i.category for i in items]) # insert categories into a set for uniqueness
], key=lambda group: (group[0].position, group[0].pk)) # a set is unsorted, so sort again by category
return context