I'm serializing a bunch of objects user Django Rest Framework and retrieving the information with angularjs on the frontend. When I check the response in the browser, my array of objects that get returned have all their fields in alphabetical order rather then the ordering instructions I gave in the backend.
What is forcing this alphabetical ordering? Django Rest Framework or angularjs? This ordering is messing up my table I'm trying to create.
data['objects'] = serializer.data
print data['objects'][0]
return Response(data)
Print output from django
{'hard_weight': 0L, 'current_count': 8020L, 'mileage': 0L, 'route_type': None, 'route': u'NO SCHEDULE', 'destination': None, 'pickup_id
': 657L, 'specials': 900000L, 'soft_weight': 0L, 'misses': 0L, 'date': datetime.date(2030, 12, 31), 'estimated_hours': Decimal('0.00'),
'estimated_hours_unload': Decimal('0.00'), 'cancel': False}
console.log of returned data:
cancel: false
current_count: 8020
date: "2030-12-31"
destination: null
estimated_hours: "0.00"
estimated_hours_unload: "0.00"
hard_weight: 0
mileage: 0
misses: 0
pickup_id: 657
route: "NO SCHEDULE"
route_type: null
soft_weight: 0
specials: 900000
Update/Solution I ended up writing this function to take in each one of my objects and put them in an array in order of a given list.
function convertObjects(objects, list){
blank = []
for(var i=0; i <objects.length; i++)
{
obj = []
object = objects[i]
for (var j=0; j<=list.length; j ++)
{
obj.push(object[list[j]])
};
blank.push(obj)
};
return blank
}