﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
8090	Problem in serializing the list returned from objects.values_list()	shavin	nobody	"#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 >
"		new	Core (Serialization)	SVN					Unreviewed	0	0	0	0		
