Code

Ticket #6748: queryset-repr.patch

File queryset-repr.patch, 759 bytes (added by korpios, 6 years ago)
  • django/db/models/query.py

    === modified file 'django/db/models/query.py'
     
    141141        return obj_dict 
    142142 
    143143    def __repr__(self): 
    144         return repr(list(self)) 
     144        # We don't want to return the repr of an enormous QuerySet, so truncate 
     145        # after hitting CHUNK_SIZE 
     146        if len(self) > CHUNK_SIZE: 
     147            return '%s ... and %d more items (%d total)' \ 
     148                % (repr(list(self[:CHUNK_SIZE])), 
     149                   len(self) - CHUNK_SIZE, 
     150                   len(self)) 
     151        else: 
     152            return repr(list(self)) 
    145153 
    146154    def __len__(self): 
    147155        # Since __len__ is called quite frequently (for example, as part of