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

The Archive Base Latest Questions

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

I have an existing file on disk (say /folder/file.txt) and a FileField model field

  • 0

I have an existing file on disk (say /folder/file.txt) and a FileField model field in Django.

When I do

instance.field = File(file('/folder/file.txt'))
instance.save()

it re-saves the file as file_1.txt (the next time it’s _2, etc.).

I understand why, but I don’t want this behavior – I know the file I want the field to be associated with is really there waiting for me, and I just want Django to point to it.

How?

  • 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:08:37+00:00Added an answer on May 27, 2026 at 6:08 am

    If you want to do this permanently, you need to create your own FileStorage class

    import os
    from django.conf import settings
    from django.core.files.storage import FileSystemStorage
    
    class MyFileStorage(FileSystemStorage):
    
        # This method is actually defined in Storage
        def get_available_name(self, name):
            if self.exists(name):
                os.remove(os.path.join(settings.MEDIA_ROOT, name))
            return name # simply returns the name passed
    

    Now in your model, you use your modified MyFileStorage

    from mystuff.customs import MyFileStorage
    
    mfs = MyFileStorage()
    
    class SomeModel(model.Model):
       my_file = model.FileField(storage=mfs)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an existing txt file, I want to be able to write stuff
Let's say I have an existing trivial XML file named 'MyData.xml' that contains the
I have an existing XML file that I would like to append without changing
I have existing Linux shared object file (shared library) which has been stripped. I
I have to correct an existing C file which has a bunch of format
I have an existing python script that, among other things checks a file against
Let's say i have 3 byte arrays, each representin a .xls file. How can
I have an existing excel file on my local machine. I need to create
I have an existing file and I want to delete it's content and then
I have an existing XSD file and I want to add a namespace. How

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.