2

edit - this is using Python 3.3 and Django 1.6

I don't know what I'm doing wrong here.

views.py

from django.core import serializers
from django.core.serializers import serialize
from django.http import HttpResponse
from itertools import chain

def test_queryjoin(request):
    jobmstquery = Jobmst.objects.using('database1').filter(jobmst_id=3296)
    jobdtlquery = Jobdtl.objects.using('database1').filter(jobdtl_id=3296)
    queryset = list(chain(jobmstquery, jobdtlquery))
    queryresults = serializers.serialize('python', queryset)
    return HttpResponse(queryset)

But when I run it I get the following error -

'module' object has no attribute 'serialize'

on this specific line -

queryresults = serializers.serialize('python', queryset)

edit - doing the following still generates the same error -

queryresults = serializers.serialize('json', jobmstquery)

same with this -

queryresults = serializers.serialize('json', Jobmst.objects.using('database1').filter(jobmst_id = 3296))

edit - This is getting weirder... it works from shell...

from django.core import serializers
from django.core.serializers import serialize
from TidalDEV.models import Jobmst
jobmstquery = Jobmst.objects.using('database1').filter(jobmst_id=3296)
queryresults = serializers.serialize('json', jobmstquery)
print (queryresults)
7
  • Why version of Python and Django are you on? (it works like a charm here, using Python 2.7 and Django 1.6) Commented Jan 3, 2014 at 3:05
  • aha! This explains something! I was wondering why it worked on my lab at home and not at work. yes, works with Python 2.6/2.7 and Django 1.6. Doesn't work with Python 3.3 and Django 1.6. Commented Jan 3, 2014 at 3:09
  • What format are you trying to serialize to? Should it really be 'python' as your first argument to the serialize function? Commented Jan 3, 2014 at 3:10
  • Doesn't matter if I do 'json', 'xml', etc. Always fails with the same error. Seems to be something changed with v3.3 compared to v2.6/2.7? Commented Jan 3, 2014 at 3:13
  • Could be a number of things I guess. I had this exact problem yesterday with Django 1.6/Python 2.7. For me, removing all filtering and sorting functions fixed it. So I just do Model.objects.all(). Of course, that's not a very satisfying answer if you need functions. Commented Jan 3, 2014 at 3:17

1 Answer 1

4

Change serializers.serialize('json', jobmstquery) to serialize('json', jobmstquery)

You are importing 'serialize' itself, so you shouldn't call it as part of the module, just on its own.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.