Commit f4749359 authored by Nicolas Joyard's avatar Nicolas Joyard

Fix API ordering of related items

parent f3eabc18
......@@ -24,10 +24,12 @@ from .models import (
Chamber,
Constituency,
Country,
Email,
Group,
Mandate,
Phone,
Representative,
WebSite,
)
......@@ -73,17 +75,28 @@ class RepresentativeViewSet(viewsets.ReadOnlyModelViewSet):
def get_queryset(self):
qs = super(RepresentativeViewSet, self).get_queryset()
qs = qs.prefetch_related(
'email_set',
'website_set',
models.Prefetch(
'email_set',
queryset=Email.objects.order_by('id')
),
models.Prefetch(
'website_set',
queryset=WebSite.objects.order_by('id')
),
models.Prefetch(
'address_set',
queryset=Address.objects.select_related('country')
.order_by('id')
),
models.Prefetch(
'phone_set',
queryset=Phone.objects.select_related('address__country')
.order_by('id')
),
'mandates',
models.Prefetch(
'mandates',
queryset=Mandate.objects.order_by('id')
)
)
return qs
......
[{"id":1,"url":"http://testserver/api/representatives/1/?format=json","slug":"hubert-pirker-1948-10-03","first_name":"Hubert","last_name":"PIRKER","full_name":"Hubert PIRKER","gender":2,"birth_place":"Gries","birth_date":"1948-10-03","photo":"http://www.europarl.europa.eu/mepphoto/2307.jpg","active":false,"cv":"Transport and security spokesman, ÖVP Delegation, European Parliament;\nsecurity spokesman, ÖVP Delegation, European Parliament (2006-2009); security spokesman (coordinator), EPP Group (1999-2004); Deputy Head of ÖVP Delegation, European Parliament (1996-2004);","contacts":{"emails":[],"phones":[],"websites":[{"url":"http://www.europarl.europa.eu/meps/en/2307/_home.html","kind":"EP"}],"address":[]},"mandates":[{"id":2,"url":"http://testserver/api/mandates/2/?format=json","group":{"id":2,"url":"http://testserver/api/groups/2/?format=json","name":"Delegation for relations with the countries of Southeast Asia and the Association of Southeast Asian Nations (ASEAN)","abbreviation":"","kind":"delegation"},"constituency":{"id":1,"url":"http://testserver/api/constituencies/1/?format=json","name":"European Parliament"},"role":"Member","begin_date":"2013-10-09","end_date":"2014-06-30"},{"id":8,"url":"http://testserver/api/mandates/8/?format=json","group":{"id":7,"url":"http://testserver/api/groups/7/?format=json","name":"Conference of Delegation Chairs","abbreviation":"","kind":"organization"},"constituency":{"id":1,"url":"http://testserver/api/constituencies/1/?format=json","name":"European Parliament"},"role":"Member","begin_date":"2006-03-21","end_date":"2009-07-13"},{"id":6,"url":"http://testserver/api/mandates/6/?format=json","group":{"id":6,"url":"http://testserver/api/groups/6/?format=json","name":"Austria","abbreviation":"AT","kind":"country"},"constituency":{"id":2,"url":"http://testserver/api/constituencies/2/?format=json","name":"Österreichische Volkspartei"},"role":"","begin_date":"1999-07-20","end_date":"2004-07-19"},{"id":4,"url":"http://testserver/api/mandates/4/?format=json","group":{"id":4,"url":"http://testserver/api/groups/4/?format=json","name":"Group of the European People's Party (Christian Democrats) and European Democrats","abbreviation":"PPE-DE","kind":"group"},"constituency":{"id":1,"url":"http://testserver/api/constituencies/1/?format=json","name":"European Parliament"},"role":"Member","begin_date":"1999-07-20","end_date":"2004-07-19"},{"id":5,"url":"http://testserver/api/mandates/5/?format=json","group":{"id":5,"url":"http://testserver/api/groups/5/?format=json","name":"Group of the European People's Party (Christian-Democratic Group)","abbreviation":"EPP","kind":"group"},"constituency":{"id":1,"url":"http://testserver/api/constituencies/1/?format=json","name":"European Parliament"},"role":"Member","begin_date":"1996-11-11","end_date":"1999-07-19"},{"id":1,"url":"http://testserver/api/mandates/1/?format=json","group":{"id":1,"url":"http://testserver/api/groups/1/?format=json","name":"Committee on Employment and Social Affairs","abbreviation":"EMPL","kind":"committee"},"constituency":{"id":1,"url":"http://testserver/api/constituencies/1/?format=json","name":"European Parliament"},"role":"Substitute","begin_date":"1997-01-16","end_date":"1999-07-19"},{"id":7,"url":"http://testserver/api/mandates/7/?format=json","group":{"id":6,"url":"http://testserver/api/groups/6/?format=json","name":"Austria","abbreviation":"AT","kind":"country"},"constituency":{"id":2,"url":"http://testserver/api/constituencies/2/?format=json","name":"Österreichische Volkspartei"},"role":"","begin_date":"1996-11-11","end_date":"1999-07-19"},{"id":3,"url":"http://testserver/api/mandates/3/?format=json","group":{"id":3,"url":"http://testserver/api/groups/3/?format=json","name":"Delegation for relations with the Member States of ASEAN, South-east Asia and the Republic of Korea","abbreviation":"","kind":"delegation"},"constituency":{"id":1,"url":"http://testserver/api/constituencies/1/?format=json","name":"European Parliament"},"role":"Member","begin_date":"1996-11-14","end_date":"1997-01-15"}]},{"id":2,"url":"http://testserver/api/representatives/2/?format=json","slug":"olle-ludvigsson-1948-10-28","first_name":"Olle","last_name":"LUDVIGSSON","full_name":"Olle LUDVIGSSON","gender":2,"birth_place":"Hälsö","birth_date":"1948-10-28","photo":"http://www.europarl.europa.eu/mepphoto/96673.jpg","active":true,"cv":"","contacts":{"emails":[{"email":"olle.ludvigsson@europarl.europa.eu","kind":"official"}],"phones":[{"number":"+322 28 45442","kind":"office phone"},{"number":"+333 88 1 75442","kind":"office phone"}],"websites":[{"url":"http://www.sap.se/olle","kind":""},{"url":"http://twitter.com/olleludvigsson","kind":"twitter"},{"url":"https://www.facebook.com/olle.ludvigsson","kind":"facebook"},{"url":"http://www.europarl.europa.eu/meps/en/96673/_home.html","kind":"EP"}],"address":[{"country":{"id":1050,"url":"http://testserver/api/countries/1050/?format=json","name":"Belgium","code":"BE"},"city":"Brussels","street":"rue Wiertz / Wiertzstraat","number":"60","postcode":"1047","floor":"14G","office_number":"257","kind":"official"},{"country":{"id":1095,"url":"http://testserver/api/countries/1095/?format=json","name":"France","code":"FR"},"city":"Strasbourg","street":"Av. du Président Robert Schuman - CS 91024","number":"1","postcode":"67070","floor":"T07","office_number":"070","kind":"official"}]},"mandates":[{"id":10,"url":"http://testserver/api/mandates/10/?format=json","group":{"id":9,"url":"http://testserver/api/groups/9/?format=json","name":"Committee on Industry, Research and Energy","abbreviation":"ITRE","kind":"committee"},"constituency":{"id":1,"url":"http://testserver/api/constituencies/1/?format=json","name":"European Parliament"},"role":"Substitute","begin_date":"2014-07-08","end_date":"9999-12-31"},{"id":9,"url":"http://testserver/api/mandates/9/?format=json","group":{"id":8,"url":"http://testserver/api/groups/8/?format=json","name":"Committee on Economic and Monetary Affairs","abbreviation":"ECON","kind":"committee"},"constituency":{"id":1,"url":"http://testserver/api/constituencies/1/?format=json","name":"European Parliament"},"role":"Member","begin_date":"2014-07-01","end_date":"9999-12-31"},{"id":17,"url":"http://testserver/api/mandates/17/?format=json","group":{"id":14,"url":"http://testserver/api/groups/14/?format=json","name":"Sweden","abbreviation":"SE","kind":"country"},"constituency":{"id":3,"url":"http://testserver/api/constituencies/3/?format=json","name":"Arbetarepartiet- Socialdemokraterna"},"role":"","begin_date":"2014-07-01","end_date":"9999-12-31"},{"id":15,"url":"http://testserver/api/mandates/15/?format=json","group":{"id":13,"url":"http://testserver/api/groups/13/?format=json","name":"Group of the Progressive Alliance of Socialists and Democrats in the European Parliament","abbreviation":"SD","kind":"group"},"constituency":{"id":1,"url":"http://testserver/api/constituencies/1/?format=json","name":"European Parliament"},"role":"Member","begin_date":"2014-07-01","end_date":"9999-12-31"},{"id":13,"url":"http://testserver/api/mandates/13/?format=json","group":{"id":11,"url":"http://testserver/api/groups/11/?format=json","name":"Delegation for relations with Bosnia and Herzegovina, and Kosovo","abbreviation":"","kind":"delegation"},"constituency":{"id":1,"url":"http://testserver/api/constituencies/1/?format=json","name":"European Parliament"},"role":"Substitute","begin_date":"2015-05-18","end_date":"9999-12-31"},{"id":12,"url":"http://testserver/api/mandates/12/?format=json","group":{"id":10,"url":"http://testserver/api/groups/10/?format=json","name":"Delegation to the EU-Serbia Stabilisation and Association Parliamentary Committee","abbreviation":"","kind":"delegation"},"constituency":{"id":1,"url":"http://testserver/api/constituencies/1/?format=json","name":"European Parliament"},"role":"Member","begin_date":"2014-07-14","end_date":"9999-12-31"},{"id":18,"url":"http://testserver/api/mandates/18/?format=json","group":{"id":14,"url":"http://testserver/api/groups/14/?format=json","name":"Sweden","abbreviation":"SE","kind":"country"},"constituency":{"id":3,"url":"http://testserver/api/constituencies/3/?format=json","name":"Arbetarepartiet- Socialdemokraterna"},"role":"","begin_date":"2009-07-14","end_date":"2014-06-30"},{"id":16,"url":"http://testserver/api/mandates/16/?format=json","group":{"id":13,"url":"http://testserver/api/groups/13/?format=json","name":"Group of the Progressive Alliance of Socialists and Democrats in the European Parliament","abbreviation":"SD","kind":"group"},"constituency":{"id":1,"url":"http://testserver/api/constituencies/1/?format=json","name":"European Parliament"},"role":"Member","begin_date":"2009-07-14","end_date":"2014-06-30"},{"id":14,"url":"http://testserver/api/mandates/14/?format=json","group":{"id":12,"url":"http://testserver/api/groups/12/?format=json","name":"Delegation for relations with Australia and New Zealand","abbreviation":"","kind":"delegation"},"constituency":{"id":1,"url":"http://testserver/api/constituencies/1/?format=json","name":"European Parliament"},"role":"Substitute","begin_date":"2009-09-17","end_date":"2013-01-10"},{"id":11,"url":"http://testserver/api/mandates/11/?format=json","group":{"id":8,"url":"http://testserver/api/groups/8/?format=json","name":"Committee on Economic and Monetary Affairs","abbreviation":"ECON","kind":"committee"},"constituency":{"id":1,"url":"http://testserver/api/constituencies/1/?format=json","name":"European Parliament"},"role":"Substitute","begin_date":"2009-07-16","end_date":"2012-01-18"}]}]
\ No newline at end of file
[{"id":1,"url":"http://testserver/api/representatives/1/?format=json","slug":"hubert-pirker-1948-10-03","first_name":"Hubert","last_name":"PIRKER","full_name":"Hubert PIRKER","gender":2,"birth_place":"Gries","birth_date":"1948-10-03","photo":"http://www.europarl.europa.eu/mepphoto/2307.jpg","active":false,"cv":"Transport and security spokesman, ÖVP Delegation, European Parliament;\nsecurity spokesman, ÖVP Delegation, European Parliament (2006-2009); security spokesman (coordinator), EPP Group (1999-2004); Deputy Head of ÖVP Delegation, European Parliament (1996-2004);","contacts":{"emails":[],"phones":[],"websites":[{"url":"http://www.europarl.europa.eu/meps/en/2307/_home.html","kind":"EP"}],"address":[]},"mandates":[{"id":1,"url":"http://testserver/api/mandates/1/?format=json","group":{"id":1,"url":"http://testserver/api/groups/1/?format=json","name":"Committee on Employment and Social Affairs","abbreviation":"EMPL","kind":"committee"},"constituency":{"id":1,"url":"http://testserver/api/constituencies/1/?format=json","name":"European Parliament"},"role":"Substitute","begin_date":"1997-01-16","end_date":"1999-07-19"},{"id":2,"url":"http://testserver/api/mandates/2/?format=json","group":{"id":2,"url":"http://testserver/api/groups/2/?format=json","name":"Delegation for relations with the countries of Southeast Asia and the Association of Southeast Asian Nations (ASEAN)","abbreviation":"","kind":"delegation"},"constituency":{"id":1,"url":"http://testserver/api/constituencies/1/?format=json","name":"European Parliament"},"role":"Member","begin_date":"2013-10-09","end_date":"2014-06-30"},{"id":3,"url":"http://testserver/api/mandates/3/?format=json","group":{"id":3,"url":"http://testserver/api/groups/3/?format=json","name":"Delegation for relations with the Member States of ASEAN, South-east Asia and the Republic of Korea","abbreviation":"","kind":"delegation"},"constituency":{"id":1,"url":"http://testserver/api/constituencies/1/?format=json","name":"European Parliament"},"role":"Member","begin_date":"1996-11-14","end_date":"1997-01-15"},{"id":4,"url":"http://testserver/api/mandates/4/?format=json","group":{"id":4,"url":"http://testserver/api/groups/4/?format=json","name":"Group of the European People's Party (Christian Democrats) and European Democrats","abbreviation":"PPE-DE","kind":"group"},"constituency":{"id":1,"url":"http://testserver/api/constituencies/1/?format=json","name":"European Parliament"},"role":"Member","begin_date":"1999-07-20","end_date":"2004-07-19"},{"id":5,"url":"http://testserver/api/mandates/5/?format=json","group":{"id":5,"url":"http://testserver/api/groups/5/?format=json","name":"Group of the European People's Party (Christian-Democratic Group)","abbreviation":"EPP","kind":"group"},"constituency":{"id":1,"url":"http://testserver/api/constituencies/1/?format=json","name":"European Parliament"},"role":"Member","begin_date":"1996-11-11","end_date":"1999-07-19"},{"id":6,"url":"http://testserver/api/mandates/6/?format=json","group":{"id":6,"url":"http://testserver/api/groups/6/?format=json","name":"Austria","abbreviation":"AT","kind":"country"},"constituency":{"id":2,"url":"http://testserver/api/constituencies/2/?format=json","name":"Österreichische Volkspartei"},"role":"","begin_date":"1999-07-20","end_date":"2004-07-19"},{"id":7,"url":"http://testserver/api/mandates/7/?format=json","group":{"id":6,"url":"http://testserver/api/groups/6/?format=json","name":"Austria","abbreviation":"AT","kind":"country"},"constituency":{"id":2,"url":"http://testserver/api/constituencies/2/?format=json","name":"Österreichische Volkspartei"},"role":"","begin_date":"1996-11-11","end_date":"1999-07-19"},{"id":8,"url":"http://testserver/api/mandates/8/?format=json","group":{"id":7,"url":"http://testserver/api/groups/7/?format=json","name":"Conference of Delegation Chairs","abbreviation":"","kind":"organization"},"constituency":{"id":1,"url":"http://testserver/api/constituencies/1/?format=json","name":"European Parliament"},"role":"Member","begin_date":"2006-03-21","end_date":"2009-07-13"}]},{"id":2,"url":"http://testserver/api/representatives/2/?format=json","slug":"olle-ludvigsson-1948-10-28","first_name":"Olle","last_name":"LUDVIGSSON","full_name":"Olle LUDVIGSSON","gender":2,"birth_place":"Hälsö","birth_date":"1948-10-28","photo":"http://www.europarl.europa.eu/mepphoto/96673.jpg","active":true,"cv":"","contacts":{"emails":[{"email":"olle.ludvigsson@europarl.europa.eu","kind":"official"}],"phones":[{"number":"+322 28 45442","kind":"office phone"},{"number":"+333 88 1 75442","kind":"office phone"}],"websites":[{"url":"http://www.sap.se/olle","kind":""},{"url":"http://twitter.com/olleludvigsson","kind":"twitter"},{"url":"https://www.facebook.com/olle.ludvigsson","kind":"facebook"},{"url":"http://www.europarl.europa.eu/meps/en/96673/_home.html","kind":"EP"}],"address":[{"country":{"id":1050,"url":"http://testserver/api/countries/1050/?format=json","name":"Belgium","code":"BE"},"city":"Brussels","street":"rue Wiertz / Wiertzstraat","number":"60","postcode":"1047","floor":"14G","office_number":"257","kind":"official"},{"country":{"id":1095,"url":"http://testserver/api/countries/1095/?format=json","name":"France","code":"FR"},"city":"Strasbourg","street":"Av. du Président Robert Schuman - CS 91024","number":"1","postcode":"67070","floor":"T07","office_number":"070","kind":"official"}]},"mandates":[{"id":9,"url":"http://testserver/api/mandates/9/?format=json","group":{"id":8,"url":"http://testserver/api/groups/8/?format=json","name":"Committee on Economic and Monetary Affairs","abbreviation":"ECON","kind":"committee"},"constituency":{"id":1,"url":"http://testserver/api/constituencies/1/?format=json","name":"European Parliament"},"role":"Member","begin_date":"2014-07-01","end_date":"9999-12-31"},{"id":10,"url":"http://testserver/api/mandates/10/?format=json","group":{"id":9,"url":"http://testserver/api/groups/9/?format=json","name":"Committee on Industry, Research and Energy","abbreviation":"ITRE","kind":"committee"},"constituency":{"id":1,"url":"http://testserver/api/constituencies/1/?format=json","name":"European Parliament"},"role":"Substitute","begin_date":"2014-07-08","end_date":"9999-12-31"},{"id":11,"url":"http://testserver/api/mandates/11/?format=json","group":{"id":8,"url":"http://testserver/api/groups/8/?format=json","name":"Committee on Economic and Monetary Affairs","abbreviation":"ECON","kind":"committee"},"constituency":{"id":1,"url":"http://testserver/api/constituencies/1/?format=json","name":"European Parliament"},"role":"Substitute","begin_date":"2009-07-16","end_date":"2012-01-18"},{"id":12,"url":"http://testserver/api/mandates/12/?format=json","group":{"id":10,"url":"http://testserver/api/groups/10/?format=json","name":"Delegation to the EU-Serbia Stabilisation and Association Parliamentary Committee","abbreviation":"","kind":"delegation"},"constituency":{"id":1,"url":"http://testserver/api/constituencies/1/?format=json","name":"European Parliament"},"role":"Member","begin_date":"2014-07-14","end_date":"9999-12-31"},{"id":13,"url":"http://testserver/api/mandates/13/?format=json","group":{"id":11,"url":"http://testserver/api/groups/11/?format=json","name":"Delegation for relations with Bosnia and Herzegovina, and Kosovo","abbreviation":"","kind":"delegation"},"constituency":{"id":1,"url":"http://testserver/api/constituencies/1/?format=json","name":"European Parliament"},"role":"Substitute","begin_date":"2015-05-18","end_date":"9999-12-31"},{"id":14,"url":"http://testserver/api/mandates/14/?format=json","group":{"id":12,"url":"http://testserver/api/groups/12/?format=json","name":"Delegation for relations with Australia and New Zealand","abbreviation":"","kind":"delegation"},"constituency":{"id":1,"url":"http://testserver/api/constituencies/1/?format=json","name":"European Parliament"},"role":"Substitute","begin_date":"2009-09-17","end_date":"2013-01-10"},{"id":15,"url":"http://testserver/api/mandates/15/?format=json","group":{"id":13,"url":"http://testserver/api/groups/13/?format=json","name":"Group of the Progressive Alliance of Socialists and Democrats in the European Parliament","abbreviation":"SD","kind":"group"},"constituency":{"id":1,"url":"http://testserver/api/constituencies/1/?format=json","name":"European Parliament"},"role":"Member","begin_date":"2014-07-01","end_date":"9999-12-31"},{"id":16,"url":"http://testserver/api/mandates/16/?format=json","group":{"id":13,"url":"http://testserver/api/groups/13/?format=json","name":"Group of the Progressive Alliance of Socialists and Democrats in the European Parliament","abbreviation":"SD","kind":"group"},"constituency":{"id":1,"url":"http://testserver/api/constituencies/1/?format=json","name":"European Parliament"},"role":"Member","begin_date":"2009-07-14","end_date":"2014-06-30"},{"id":17,"url":"http://testserver/api/mandates/17/?format=json","group":{"id":14,"url":"http://testserver/api/groups/14/?format=json","name":"Sweden","abbreviation":"SE","kind":"country"},"constituency":{"id":3,"url":"http://testserver/api/constituencies/3/?format=json","name":"Arbetarepartiet- Socialdemokraterna"},"role":"","begin_date":"2014-07-01","end_date":"9999-12-31"},{"id":18,"url":"http://testserver/api/mandates/18/?format=json","group":{"id":14,"url":"http://testserver/api/groups/14/?format=json","name":"Sweden","abbreviation":"SE","kind":"country"},"constituency":{"id":3,"url":"http://testserver/api/constituencies/3/?format=json","name":"Arbetarepartiet- Socialdemokraterna"},"role":"","begin_date":"2009-07-14","end_date":"2014-06-30"}]}]
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment