Opened 16 years ago

Last modified 14 years ago

#9365 closed

Permutated columns when using Paginator with ValuesQuerySet — at Initial Version

Reported by: micval@… Owned by: nobody
Component: Database layer (models, ORM) Version: 1.0
Severity: Normal Keywords: paginator valuesqueryset
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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.

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top