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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:38:00+00:00 2026-05-24T13:38:00+00:00

I am working on a Django project in which users should be allowed to

  • 0

I am working on a Django project in which users should be allowed to upload multiple images at once. That portion of the project will likely be handled by SWFUpload, unless you have a better suggestion.

The image renaming, resizing, and thumbnail creation will be handled by django-stdimage2.

The Problem
django-stdimage2 renames each image using the field name and object primary key.
If five images exist for gear row with primary key 1, all five images will be renamed “image_1.jpeg”.

Before I introduce a possible solution, here are my models.
Basically, one gear row can have many gear_image rows.

class gear(models.Model):
       id = models.AutoField(primary_key=True)
       model = models.CharField(max_length=100)

class gear_images(models.Model):
       id = models.AutoField(primary_key=True)
       gear_id = models.ForeignKey(gear)
       image = StdImageField(upload_to='images/gear', blank=True, size=(640, 480, True), thumbnail_size=(100, 100, True))

A Solution
I was thinking of adding a timestamp, in milliseconds and rounded, to the filename.
I’m neither a Python or Django pro but I poked around in django-stdimage2’s fields.py file and I think I located the code I need to edit to make this work.
The two lines of code that are commented out are my proposed solutions:

def _rename_resize_image(self, instance=None, **kwargs):
    '''
    Renames the image, and calls methods to resize and create the thumbnail
    '''
    if not kwargs.get('raw', None):
        if getattr(instance, self.name):
            filename = getattr(instance, self.name).path
            ext = os.path.splitext(filename)[1].lower().replace('jpg', 'jpeg')
            # time_stamp = int(round(time.time() * 1000))
            # dst = self.generate_filename(instance, '%s_%s_%s%s' % (self.name, instance._get_pk_val(), time_stamp, ext))
            dst = self.generate_filename(instance, '%s_%s%s' % (self.name, instance._get_pk_val(), ext))
            dst_fullpath = os.path.join(settings.MEDIA_ROOT, dst)
            if os.path.normcase(os.path.abspath(filename)) != os.path.normcase(os.path.abspath(dst_fullpath)):
                os.rename(filename, dst_fullpath)
                if self.size:
                    self._resize_image(dst_fullpath, self.size)
                if self.thumbnail_size:
                    thumbnail_filename = self._get_thumbnail_filename(dst_fullpath)
                    shutil.copyfile(dst_fullpath, thumbnail_filename)
                    self._resize_image(thumbnail_filename, self.thumbnail_size)
                setattr(instance, self.attname, dst)
                instance.save()

Each image name would look something like: image_1_159753456.jpeg
Do you think this is a good work-around? I am open to other ideas also.

Thank you 🙂

  • 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-24T13:38:01+00:00Added an answer on May 24, 2026 at 1:38 pm

    I do not think you have a problem here at all.

    django-stdimage{2} will rename to the object id of your gear_images model, not its parent gear model. So one gear can have many images, each will have the gear_images pk appended to the filename.

    So really, you only have a problem if it’s important to you to use the gear model’s pk in the filename instead of the gear_images pk. If you’re ok with the latter, then you don’t need to do anything, it should just work.

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

Sidebar

Related Questions

I am working on an django application that will return what historically was a
I'm working on a project in django which calls for having separate groups of
Greetings, I am currently working on a long term project that uses Django 1.1.1,
I'm working on an intranet django project (not using GAE) for a company that
I'm working on a project, using Python/Django running on a Virtual Private Server, which
I'm working on a project in Python/Django which uses ReportLab's SimpleDocTemplate to generate PDF
I'm working on a Google App Engine project using Django. I noticed that for
I am working through the examples in a Django book that I have, but
I am working on a django project, where I want to implement a signal
I am working on a django project (my first), and in one of my

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.