Opened 16 years ago

Last modified 10 years ago

#8090 closed

Problem in serializing the list returned from objects.values_list() — at Version 2

Reported by: shavin Owned by: nobody
Component: Core (Serialization) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Ramiro Morales)

#when i run this code:

from StudentsSite.Names.models import *
from django.utils import simplejson

lstSchoolCertificateNames = SchoolCertificateName.objects.values_list('school_certificate_name', flat=True)

serializedlist=simplejson.dumps(lstSchoolCertificateNames, encoding='utf-8');

#this is given as error:

Environment:

Request Method: GET
Request URL: http://localhost:8000/StudentsSite/Students/Search/
Django Version: 1.0-alpha-SVN-8161
Python Version: 2.5.2
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'StudentsSite.Students',
 'django.contrib.admin',
 'django.contrib.databrowse',
 'StudentsSite.Names']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.middleware.doc.XViewMiddleware')


Traceback:
File "C:\Python25\lib\site-packages\django\core\handlers\base.py" in get_response
  87.                 response = callback(request, *callback_args, **callback_kwargs)
File "C:\Users\shavin\django\StudentsSite\..\StudentsSite\Students\views.py" in searchForm
  37.         lstSchoolCertificateNames2=simplejson.dumps(lstSchoolCertificateNames, encoding='utf-8');
File "C:\Python25\lib\site-packages\django\utils\simplejson\__init__.py" in dumps
  236.         return _default_encoder.encode(obj)
File "C:\Python25\lib\site-packages\django\utils\simplejson\encoder.py" in encode
  366.         chunks = list(self.iterencode(o))
File "C:\Python25\lib\site-packages\django\utils\simplejson\encoder.py" in _iterencode
  316.             for chunk in self._iterencode_default(o, markers):
File "C:\Python25\lib\site-packages\django\utils\simplejson\encoder.py" in _iterencode_default
  322.         newobj = self.default(o)
File "C:\Python25\lib\site-packages\django\utils\simplejson\encoder.py" in default
  343.         raise TypeError("%r is not JSON serializable" % (o,))

Exception Type: TypeError at /StudentsSite/Students/Search/
Exception Value: [u'icse'] is not JSON serializable

#AND when this is done

from StudentsSite.Names.models import *
from django.core.serializers import serialize

lstSchoolCertificateNames = SchoolCertificateName.objects.values_list('school_certificate_name', flat=True)

serializedlist=serialize('json',lstSchoolCertificateNames, encoding='utf-8')


#it gives this error:

Environment:

Request Method: GET
Request URL: http://localhost:8000/StudentsSite/Students/Search/
Django Version: 1.0-alpha-SVN-8161
Python Version: 2.5.2
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'StudentsSite.Students',
 'django.contrib.admin',
 'django.contrib.databrowse',
 'StudentsSite.Names']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.middleware.doc.XViewMiddleware')


Traceback:
File "C:\Python25\lib\site-packages\django\core\handlers\base.py" in get_response
  87.                 response = callback(request, *callback_args, **callback_kwargs)
File "C:\Users\shavin\django\StudentsSite\..\StudentsSite\Students\views.py" in searchForm
  38.         lstSchoolCertificateNames2=serialize('json', lstSchoolCertificateNames)
File "C:\Python25\lib\site-packages\django\core\serializers\__init__.py" in serialize
  72.     s.serialize(queryset, **options)
File "C:\Python25\lib\site-packages\django\core\serializers\base.py" in serialize
  40.             for field in obj._meta.local_fields:

Exception Type: AttributeError at /StudentsSite/Students/Search/
Exception Value: 'unicode' object has no attribute '_meta'

#and i also found that values_list() function was returning an object of the type <django.db.models.query.ValuesListQuerySet >

Change History (2)

comment:1 by shavin, 16 years ago

comment:2 by Ramiro Morales, 16 years ago

Description: modified (diff)
Version: 1.0-alphaSVN

Reformatted description, set Version field to SVN (as per the Django Version: 1.0-alpha-SVN-8161 fragment)

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