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 5957981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:28:42+00:00 2026-05-22T18:28:42+00:00

Summary: The problem is that I cannot access the thumbnail image from a nested

  • 0

Summary: The problem is that I cannot access the thumbnail image from a nested class in the serialized model and I don’t know how to expose it in the JSON response.

Description: I am trying to serialize my Thing model to JSON and it works, in a fashion. I get the following in my JSON response:

// JSON response
[
    {
        pk: 1
        model: "base.thing"
        fields: {
            active: true
            created_at: "2011-04-13 07:18:05"
            num_views: 1
            file: "things/5216868239_b53b8d5e80_b.jpg"
            title: "ding ding ding"
        }
    }
]

I just started using django-imagekit to manipulate the Thing images to thumbnail sizes and it works in normal usage, i.e. running ‘thing.thumbnail_image.url’ in a template returns the correct url to the thumbnail image.

The sandbox code I’m playing around with:

# base/models.py
from django.db import models
from imagekit.models import ImageModel

class Thing(ImageModel):
    title = models.CharField(max_length=30)
    file = models.ImageField(upload_to='things')
    created_at = models.DateTimeField(auto_now_add=True)
    active = models.BooleanField()
    num_views = models.PositiveIntegerField(editable=False, default=0)

    def __unicode__(self):
        return self.title

    class IKOptions:
        spec_module = 'base.specs'
        image_field = 'file'
        save_count_as = 'num_views'

# base/views.py
from django.views.generic.base import View
from django.views.generic.list import MultipleObjectTemplateResponseMixin, ListView

from base.models import Thing    
from django import http
from django.utils import simplejson as json

from utils import JsonResponse

class JSONResponseMixin(object):
    def render_to_response(self, context):
        "Returns a JSON response containing 'context' as payload"
        return self.get_json_response(context)

    def get_json_response(self, content, **httpresponse_kwargs):
        "Construct an `HttpResponse` object."
        return JsonResponse(content['thing_list']) # I can't serialize the content object by itself

class ThingsView(JSONResponseMixin, ListView):
    model = Thing
    context_object_name = "thing_list"
    template_name = "base/thing_list.html"

    def render_to_response(self, context):
        if self.request.GET.get('format', 'html') == 'json':
            return JSONResponseMixin.render_to_response(self, context)
        else:
            return ListView.render_to_response(self, context)

# base/specs.py
from imagekit.specs import ImageSpec
from imagekit import processors

class ResizeThumb(processors.Resize):
    width = 100
    height = 75
    crop = True

class ResizeDisplay(processors.Resize):
    width = 600

class EnchanceThumb(processors.Adjustment):
    contrast = 1.2
    sharpness = 1.1

class Thumbnail(ImageSpec):
    access_as = 'thumbnail_image'
    pre_cache = True
    processors = [ResizeThumb, EnchanceThumb]

class Display(ImageSpec):
    increment_count = True
    processors = [ResizeDisplay]

# utils.py
from django.core.serializers import json, serialize
from django.db.models.query import QuerySet
from django.http import HttpResponse
from django.utils import simplejson

class JsonResponse(HttpResponse):
    def __init__(self, object):
        if isinstance(object, QuerySet):
            content = serialize('json', object)
        else:
            content = simplejson.dumps(
                object, indent=2, cls=json.DjangoJSONEncoder,
                ensure_ascii=False)
        super(JsonResponse, self).__init__(
            content, content_type='application/json')

I appreciate any help with this, it’s been blocking me for a day.

Best regards-

Using versions:
Django 1.3
PIL 1.1.7
django-imagekit 0.3.6
simplejson 2.1.3

  • 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-22T18:28:42+00:00Added an answer on May 22, 2026 at 6:28 pm

    I couldn’t figure out how to expose the inner class over JSON so I chose an alternative way of doing it and dropping django-imagekit and manually resizing the image to a thumbnail and saving it in the model’s save() function.

    im = ImageOps.fit(im, (sizes['thumbnail']['width'], sizes['thumbnail']['height'],), method=Image.ANTIALIAS)
    thumbname = filename + "_" + str(sizes['thumbnail']['width']) + "x" + str(sizes['thumbnail']['height']) + ".jpg"
    im.save(fullpath + '/' + thumbname)
    

    It’s a less than clean approach but it works for now.

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

Sidebar

Related Questions

Summary What's the best way to ensure a table cell cannot be less than
Summary Hi All, OK, further into my adventures with custom controls... In summary, here
SUMMARY: When browsing an ASP.NET website using Windows Explorer, popup windows do not borrow
Summary: I'm developing a persistent Java web application, and I need to make sure
Summary: Can I program a thick client game in C without reinventing wheels ,
Summary: I'm able to compile a RAD Studio 2009 project using MSBuild on a
Executive Summary: When assertion errors are thrown in the threads, the unit test doesn't
I need to have a summary field in each page of the report and
What references offer a good summary/tutorial for using RDF/OWL? There seem to be enough
Is there an easy way to get a conflict summary after running a cvs

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.