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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T17:53:01+00:00 2026-05-29T17:53:01+00:00

Some additional features were added to a django application, and as a result the

  • 0

Some additional features were added to a django application, and as a result the upload_to function also expanded.

Since django by default stores filenames in the database, and files on disk, no harm has been done – new files are named using a new upload_to function, while old files continue to work.

However, this is messy – we end up in a situation with files like

/media/userID/oldfilename.pdf 

and

/media/app/userID/projectID/newfilename.pdf 

Is there a way to bulk rename those files? I guess it could be done by iterating through the database, checking if the path in FileField matches the result of current upload_to, and if not, rename.. it seems like a common problem, so perhaps there is a more generic way out there?

  • 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-29T17:53:10+00:00Added an answer on May 29, 2026 at 5:53 pm

    The simple solution is to write a custom Django management command. You can run the command using Django’s standard manage.py.

    Something like this:

    from django.core.management.base import BaseCommand, CommandError
    from example.models import YourModel
    
    class Command(BaseCommand):
        args = ''
        help = ''
    
        def handle(self, *args, **options):
    
            # Get all objects
            objects = YourModel.objects.all()
    
            for object in objects: # For each object
    
                # If old file path:
                if not 'userID/projectID' in objects.filefield.name:
                    # Move the file, eg usign shutil http://docs.python.org/library/shutil.html#shutil.move
                    # Update filefield
                    # save object
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a flash player that loads in some additional features from flash files
We have subclassed the Silverlight Application class to add some additional functionality and then
Is there some additional configuration needed before I can set thread priorities in a
I'm storing some additional per-user information using the AUTH_PROFILE_MODULE . We can access the
I wish to load some additional data from javascript in an HTML page. The
I am trying to add some additional logic to the 'Promoted to front page'
I'm trying to add some additional key/value pairs to an NSMutableDictionary, using: Tag *tag1
I'm experimenting with TextArea and inheritance to implement some additional functionality on the protected
[Edited: After cross-testing on a fresh machine and some additional research, this appears to
I've created an extension method for SqlCommand that allows some additional work before executing

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.