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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:31:08+00:00 2026-06-04T20:31:08+00:00

I have a this model… class MyModel(models.Model): … file = models.FileField(upload_to=’files/’,null=True, blank=True) … when

  • 0

I have a this model…

class MyModel(models.Model):
    ...
    file = models.FileField(upload_to='files/',null=True, blank=True)
    ...

when i upload a file, example file name is docfile.doc. when i change the file or i rewrite it and upload again docfile.doc the file will become docfile_1.doc and the old docfile.doc is still exist.

i am doing the uploading and saving data in django-admin

my question is, how can i remove the old docfile.doc if i upload the new docfile.doc and the file name is still docfile.doc?

can anyone help me in my case? thanks in advance

i try this one :

def content_file_name(instance, filename):
    print instance
    print filename
    file = os.path.exists(filename)
    print file
    if file:
        os.remove(filename)
    return "file/"+str(filename)

 class MyModel(models.Model):
        ...
        file = models.FileField(upload_to=content_file_name,null=True, blank=True)
        ...

but nothing happend, when i upload docfile.doc again, it will become docfile_1.doc and the old docfile.doc still exist.

  • 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-06-04T20:31:10+00:00Added an answer on June 4, 2026 at 8:31 pm

    i got it… i use this

    def content_file_name(instance, filename):
        print instance
        print filename
        file = os.path.exists("media/file/"+str(filename))
        print file
        if file:
            os.remove("media/file/"+str(filename))
        return "file/"+str(filename)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Actually have this model: class MusicFile(models.Model): file = models.FileField(upload_to=files) def exist_in_playlist(self, playlist_id): exist =
Lets say I have this model class Egg(models.Model): file = FileField(upload_to='media') img = ImageField(upload_to='media')
I have this model class Vacancy(models.Model): user = models.ForeignKey(User, null=True, blank=True, default = None)
If I have this model: class Person(models.Model): name=models.CharField(max_length=28) mother=models.ForeignKey(self,null=True,blank=True) I am trying to make
I have this model: class blog(models.Model): user = models.ForeignKey(User) mail = models.EmailField(max_length=60, null=False, blank=False)
I have this model: class Category(models.Model): name = models.CharField() description = models.CharField(blank=True) parent =
I have this model in django: class JournalsGeneral(models.Model): jid = models.AutoField(primary_key=True) code = models.CharField(Code,
I have this model: class Journals(models.Model): jid = models.AutoField(primary_key=True) code = models.CharField(Code, max_length=50) name
Imagine you have this model: class Category(models.Model): node_id = models.IntegerField(primary_key = True) type_id =
I have this model: class MedicoImage(models.Model): medico = models.ForeignKey(Medico) imagem = models.ImageField(max_length=300,upload_to='img_medico') I want

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.