• Home
  • Django
  • How to prevent Django from changing file name when a file with that name already exists?

How to prevent Django from changing file name when a file with that name already exists?

linkaiyi
Follow

class OverwriteStorage(FileSystemStorage):

def get_available_name(self, name):
    if self.exists(name):
        os.remove(os.path.join(SOME_PATH, name))
    return name

fs = OverwriteStorage(location=SOME_PATH)

class YourModel(models.Model):
image_file = models.ImageField(storage=fs)

Object has 0 attachments

Was this article helpful?

This article is viewed 34 times!

0 Comments

Leave a Comment

Support