Paginator in python django crashes on dict
Question: I have 2 types of gathered data from database:

One is `[<NaseljenoMesto: NaseljenoMesto object>, <NaseljenoMesto:
NaseljenoMesto object>]`

And another is: `[{'naseljenomesto_drzava__naziv': u'Srbija', 'sifraMesta':
u'ZR', 'nazivMesta': u'Zrenjanin', 'id': 3}, {'naseljenomesto _drzava__naziv':
u'Srbija', 'sifraMesta': u'BG', 'nazivMesta': u'Beograd', 'id': 1}]`

First is QuerySet type and another is ValuesQuerySet.

Now i have Paginator: `paginator = Paginator(filteredData, rowsPerPage)`

In first case paginator works but in second crashes. How to correct this?

## EDIT

    
    
    Internal Server Error: /TestProjekat/main/getFormData/
    Traceback (most recent call last):
      File "C:\Python27\lib\site-packages\django\core\handlers\base.py", line 115, in get_response
        response = callback(request, *callback_args, **callback_kwargs)
      File "C:\Users\Milan\Desktop\DA_LI_RADI\Test projekat\st_forms\views.py", line 238, in getFormData
        serializedData = serializers.serialize("json", data)
      File "C:\Python27\lib\site-packages\django\core\serializers\__init__.py", line 99, in serialize
        s.serialize(queryset, **options)
      File "C:\Python27\lib\site-packages\django\core\serializers\base.py", line 46, in serialize
        concrete_model = obj._meta.concrete_model
    AttributeError: 'dict' object has no attribute '_meta'
    

## EDIT 2

    
    
    paginator = Paginator(filteredData, rowsPerPage)
    
    try:
        data = paginator.page(page)
    except PageNotAnInteger:
        data = paginator.page(1)
    except EmptyPage:
        data = paginator.page(paginator.num_pages)
    
    serializedData = serializers.serialize("json", data)
    

## NEW ERROR

    
    
    Traceback (most recent call last):
      File "C:\Python27\lib\site-packages\django\core\handlers\base.py", line 115, in get_response
        response = callback(request, *callback_args, **callback_kwargs)
      File "C:\Users\Milan\Desktop\DA_LI_RADI\Test projekat\st_forms\views.py", line 238, in getFormData
        serializedData = json.dumps({'data': data})
      File "C:\Python27\lib\json\__init__.py", line 243, in dumps
        return _default_encoder.encode(obj)
      File "C:\Python27\lib\json\encoder.py", line 207, in encode
        chunks = self.iterencode(o, _one_shot=True)
      File "C:\Python27\lib\json\encoder.py", line 270, in iterencode
        return _iterencode(o, 0)
      File "C:\Python27\lib\json\encoder.py", line 184, in default
        raise TypeError(repr(o) + " is not JSON serializable")
    TypeError: <Page 1 of 1> is not JSON serializable
    


Answer: The problem is not the pagination, but the way you serialize your data:
`serializers.serialize` is built to serialize Django model instances (from a
list or a `QuerySet`), nothing else. You can use the `json` module from the
python stdlib to serialize 'raw' dictionaries, try for example:

    
    
    import json
    print json.dumps({'your': 'dict'})
    

You might need to convert the `ValuesQuerySet` to a vanilla list-of-dicts to
convince the `json` module to work, though:

    
    
    # [...]
    data = paginator.page(1)
    print json.dumps(list(data))
    

