Changes between Initial Version and Version 1 of Ticket #9365


Ignore:
Timestamp:
Oct 14, 2008, 9:44:32 PM (16 years ago)
Author:
Malcolm Tredinnick
Comment:

Fixed description. Please use the preview button to check your description in the future. Wiki syntax isn't like bulletin board syntax or whatever it was you were using and the text was unfortunately fairly unreadable.

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #9365 – Description

    initial v1  
    1 I have this model:[[BR]]
    2 [[BR]]
     1I have this model:
     2
     3{{{
     4#!python
     5class 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
     12When 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
     16docs = Document.objects.values('id','filename','filesize','keywords')
     17}}}
    318
    419
    5 class Document(models.Model):[[BR]]
     20But when feeding this list directly to Paginator, the columns get permutated, e.g.: `Paginator(docs,3,3,True).page(1).object_list` gives:
    621
    7     filename    = models.CharField(max_length=1000)[[BR]]
     22{{{
     23#!python
     24[{'keywords': 161, 'id': 1, 'filesize': u'sample file'},
     25{'keywords': 162, 'id': 2, 'filesize': u'another sample file'},
     26{'keywords': 163, 'id': 3, 'filesize': u'sample file'}]
     27}}}
    828
    9     filesize    = models.IntegerField()[[BR]]
     29If I "evaluate" docs first, the columns get their correct values:
    1030
    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}}}
    1437
    1538
    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.
     39I use `l = len(docs)` workaround in my views, which does the trick, but this behaviour puzzles me a little bit.
Back to Top