| 1 | | I have this model:[[BR]] |
| 2 | | [[BR]] |
| | 1 | I have this model: |
| | 2 | |
| | 3 | {{{ |
| | 4 | #!python |
| | 5 | class Document(models.Model): |
| | 6 | filename = models.CharField(max_length=1000) |
| | 7 | filesize = models.IntegerField() |
| | 8 | keywords = models.CharField(max_length=1000) |
| | 9 | content = models.TextField() |
| | 10 | }}} |
| | 11 | |
| | 12 | When selecting documents I don't want the content field to be selected (for performance issues), so I use values like this: |
| | 13 | |
| | 14 | {{{ |
| | 15 | #!python |
| | 16 | docs = Document.objects.values('id','filename','filesize','keywords') |
| | 17 | }}} |
| 11 | | keywords = models.CharField(max_length=1000)[[BR]] |
| 12 | | |
| 13 | | content = models.TextField()[[BR]] |
| | 31 | {{{ |
| | 32 | #!python |
| | 33 | [{'keywords': u'sample file', 'id': 1, 'filesize': 161}, |
| | 34 | {'keywords': u'another sample file', 'id': 2, 'filesize': 162}, |
| | 35 | {'keywords': u'sample file', 'id': 3, 'filesize': 163}] |
| | 36 | }}} |
| 16 | | When selecting documents I don't want the content field to be selected (for performance issues), so I use values like this:[[BR]] |
| 17 | | [[BR]] |
| 18 | | |
| 19 | | |
| 20 | | docs = Document.objects.values('id','filename','filesize','keywords')[[BR]] |
| 21 | | [[BR]] |
| 22 | | |
| 23 | | |
| 24 | | But when feeding this list directly to Paginator, the columns get permutated, e.g.:[[BR]] |
| 25 | | [[BR]] |
| 26 | | |
| 27 | | |
| 28 | | Paginator(docs,3,3,True).page(1).object_list gives:[[BR]] |
| 29 | | |
| 30 | | [{'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'}][[BR]] |
| 31 | | [[BR]] |
| 32 | | |
| 33 | | |
| 34 | | If I "evaluate" docs first, the columns get their correct values:[[BR]] |
| 35 | | |
| 36 | | [{'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}][[BR]] |
| 37 | | [[BR]] |
| 38 | | |
| 39 | | |
| 40 | | I use "l = len(docs)" workaround in my views, which does the trick, but this behaviour puzzles me a little bit. |
| | 39 | I use `l = len(docs)` workaround in my views, which does the trick, but this behaviour puzzles me a little bit. |