Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6891647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:26:10+00:00 2026-05-27T06:26:10+00:00

Django has a built in serialization functionality which allows you to serialize any query

  • 0

Django has a built in serialization functionality which allows you to serialize any query result set into JSON:

json_serializer = serializers.get_serializer("json")()
json_serializer.serialize(queryset, ensure_ascii=False)

This produces output such as:

[
  {
    "pk": 1, 
    "model": "app_name.model_name", 
    "fields": {
      "field_name": "value", 
      (...)
    }
  }
]

If you want to pass this JSON object over to an ExtJS driven application you run into a problem, because ExtJS expects its JSON to be formatted differently:

{
    "total": 100,
    "success": true,
    "objects": [
        {
            "id": 1,
            "field_name": "value",
            (...)
        }
    ]
}

There are 2 main differences: the additional meta-data (success, total) and the IDs of the objects which are provided together with other fields in Ext, but not in Django.

There are many possible ways to make one or the other format conform with the second, but what do you consider to be the best way to make this work? Is it a special serializer on the Django side, or maybe a special reader on the ExtJS side…

What do you think is the best way to solve this problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T06:26:11+00:00Added an answer on May 27, 2026 at 6:26 am

    I found a solution which is able to serialize objects, which contain QuerySet as attributes. It’s comes from traddicts.org blog, but you can now find it on GitHub:

    https://github.com/datamafia/django-query-json-serializer/blob/master/JSONSerializer.py

    I further modified the code to work recursively, so in effect I can do the following:

    users = User.objects.all()
    response = {}
    response['success'] = True
    response['users'] = users
    json_serialize(response)
    json_serialize(response, serialize_related=True)
    json_serialize(response, serialize_related=True, ignored=['users.groups'])
    json_serialize(response, serialize_related=True, ignored=['users.groups.permissions'])
    

    I like your answer Thomas, but I needed something which would be even more flexible.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have Django project on Dreamhost server which has several views that returns Json
Web frameworks such as Rails and Django has built-in support for slugs which are
Web frameworks such as Rails and Django has built-in support for slugs which are
I've been using the built-in Django comments system which has been working great. On
I am using the built in comment system with Django but it has started
My Django app has a Person table, which contains the following text in a
I am making a custom form object in Django which has an overrided __init__
I has a Django view which is accessed through an AJAX call. It's a
I built a Django application for a client about a year ago. He has
I'm using django-piston for my REST json api, and I have it all set

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.