Opened 16 years ago

Last modified 9 years ago

#8090 closed

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

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

#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

  1. response = callback(request, *callback_args, callback_kwargs)

File "C:\Users\shavin\django\StudentsSite\..\StudentsSite\Students\views.py" in searchForm

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

File "C:\Python25\lib\site-packages\django\utils\simplejson\init.py" in dumps

  1. return _default_encoder.encode(obj)

File "C:\Python25\lib\site-packages\django\utils\simplejson\encoder.py" in encode

  1. chunks = list(self.iterencode(o))

File "C:\Python25\lib\site-packages\django\utils\simplejson\encoder.py" in _iterencode

  1. for chunk in self._iterencode_default(o, markers):

File "C:\Python25\lib\site-packages\django\utils\simplejson\encoder.py" in _iterencode_default

  1. newobj = self.default(o)

File "C:\Python25\lib\site-packages\django\utils\simplejson\encoder.py" in default

  1. 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

  1. response = callback(request, *callback_args, callback_kwargs)

File "C:\Users\shavin\django\StudentsSite\..\StudentsSite\Students\views.py" in searchForm

  1. lstSchoolCertificateNames2=serialize('json', lstSchoolCertificateNames)

File "C:\Python25\lib\site-packages\django\core\serializers\init.py" in serialize

  1. s.serialize(queryset, options)

File "C:\Python25\lib\site-packages\django\core\serializers\base.py" in serialize

  1. 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 (0)

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