From e6df0ee439db9fa95c103bc0fa3fbf98bf1f92e2 Mon Sep 17 00:00:00 2001
From: Nicolas Joyard <joyard.nicolas@gmail.com>
Date: Tue, 28 Jun 2016 20:34:02 +0200
Subject: [PATCH] Force a specific ordering of entries

---
 memopol/views/representative_detail.py | 5 +++--
 memopol/views/representative_mixin.py  | 6 +++---
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/memopol/views/representative_detail.py b/memopol/views/representative_detail.py
index 7b484e34..4ced478a 100644
--- a/memopol/views/representative_detail.py
+++ b/memopol/views/representative_detail.py
@@ -59,8 +59,9 @@ class RepresentativeDetail(RepresentativeViewMixin, generic.DetailView):
 
         c['votes'] = c['object'].votes.all()
         c['mandates'] = c['object'].mandates.all()
-        c['positions'] = c['object'].positions.filter(
-            published=True).prefetch_related('tags')
+        c['positions'] = c['object'].positions.filter(published=True) \
+            .prefetch_related('tags') \
+            .order_by('-datetime', 'pk')
 
         c['position_form'] = PositionForm(
             initial={'representative': self.object.pk})
diff --git a/memopol/views/representative_mixin.py b/memopol/views/representative_mixin.py
index 55547c69..42fe1135 100644
--- a/memopol/views/representative_mixin.py
+++ b/memopol/views/representative_mixin.py
@@ -20,9 +20,9 @@ class RepresentativeViewMixin(object):
         """
         Prefetch Mandates with their Group and Constituency with Country.
         """
-        mandates = Mandate.objects.order_by(
-            '-end_date').select_related('constituency__country', 'group',
-            'group__chamber')
+        mandates = Mandate.objects.order_by('-end_date', '-begin_date',
+            'group__kind', 'group__name').select_related('group',
+            'group__chamber', 'constituency__country')
         return queryset.prefetch_related(
             models.Prefetch('mandates', queryset=mandates))
 
-- 
GitLab