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

  • Home
  • SEARCH
  • 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 7192055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:51:34+00:00 2026-05-28T19:51:34+00:00

I’m using imagekit provided at: imagekit So, I’ve defined two class model: class Photo(models.Model):

  • 0

I’m using imagekit provided at: imagekit

So, I’ve defined two class model:

class Photo(models.Model):
    #photo_wrapper = models.ForeignKey(PhotoWrapper, blank=True, null=True)
    original_image = models.ImageField(upload_to='static/photos')
    thumbnail = ImageSpec([Adjust(contrast=1.2, sharpness=1.1),
            resize.Crop(50, 50)], image_field='original_image',
            format='JPEG', quality=90)
    num_views = models.PositiveIntegerField(editable=False, default=0)

    class IKOptions:
        # This inner class is where we define the ImageKit options for the model
        spec_module = 'myspecs.specs'
        cache_dir = 'static/photos'
        image_field = 'original_image'
        save_count_as = 'num_views'

class Country(models.Model):       
    country_name = models.CharField(max_length=250)        
    country_photo = models.ForeignKey(Photo, blank=True, null=True)

    def __unicode__(self):
            return '%s' % self.country_name 

The problem is that each photo is created in the “static/photos” path.
My intent is to save the image and the thumbnail with a dynamic path, based on the country name..

For example, for the country “Argentina”, the dynamic path will be “static/photos/Argentina/”

How can I accomplish that?

  • 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-28T19:51:35+00:00Added an answer on May 28, 2026 at 7:51 pm

    It looks like you’re mixing two different versions of ImageKit. The newer versions (1.0+) no longer use the inner IKOptions class, so all of that is being ignored. (The save_count_as functionality was also removed.)

    If you want to control the cache filename, the ImageSpec constructor accepts a cache_to kwarg which—like ImageField‘s upload_to—can be a callable. Here’s the current documentation for cache_to:

    Specifies the filename to use when saving the image
    cache file. This is modeled after ImageField's ``upload_to`` and
    can be either a string (that specifies a directory) or a
    callable (that returns a filepath). Callable values should
    accept the following arguments:
    
        - instance -- The model instance this spec belongs to
        - path -- The path of the original image
        - specname -- the property name that the spec is bound to on
            the model instance
        - extension -- A recommended extension. If the format of the
            spec is set explicitly, this suggestion will be
            based on that format. if not, the extension of the
            original file will be passed. You do not have to use
            this extension, it's only a recommendation.
    

    So you’ll just have to create a function that accepts those arguments and returns the path you want, and use that in your model like so:

    class Photo(models.Model):
        thumbnail = ImageSpec(..., cache_to=my_cache_to_function)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Paperclip to handle profile photo uploads in my app. They upload
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

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.