I have this model:
class Document(models.Model):
filename = models.CharField(max_length=1000)
filesize = models.IntegerField()
keywords = models.CharField(max_length=1000)
content = models.TextField()
When selecting documents I don't want the content field to be selected (for performance issues), so I use values like this:
docs = Document.objects.values('id','filename','filesize','keywords')
But when feeding this list directly to Paginator, the columns get permutated, e.g.: Paginator(docs,3,3,True).page(1).object_list gives:
[{'keywords': 161, 'id': 1, 'filesize': u'sample file'},
{'keywords': 162, 'id': 2, 'filesize': u'another sample file'},
{'keywords': 163, 'id': 3, 'filesize': u'sample file'}]
If I "evaluate" docs first, the columns get their correct values:
[{'keywords': u'sample file', 'id': 1, 'filesize': 161},
{'keywords': u'another sample file', 'id': 2, 'filesize': 162},
{'keywords': u'sample file', 'id': 3, 'filesize': 163}]
I use l = len(docs) workaround in my views, which does the trick, but this behaviour puzzles me a little bit.