
import os.path
from django.core.files.storage import FileSystemStorage

class OverwriteStorage(FileSystemStorage):

    def get_available_name(self, name):
        return name

    def _save(self, name, content):
        full_path = self.path(name)
        # make sure an existing file is replaced by removing the
        # original file first
        if os.path.exists(full_path):
            os.remove(full_path)
        return super(OverwriteStorage, self)._save(name, content)



import os.path
from django.core.files.storage import FileSystemStorage

class OverwriteStorage(FileSystemStorage):

    def get_available_name(self, name, max_length=None):
        return name

    def _save(self, name, content):
        full_path = self.path(name)
        # make sure an existing file is replaced by removing the
        # original file first
        if os.path.exists(full_path):
            os.remove(full_path)
        return super(OverwriteStorage, self)._save(name, content)


Migrate to new Storage API
Migrate to new Storage API

for Django 1.8

  
  import os.path
  from django.core.files.storage import FileSystemStorage
  
  class OverwriteStorage(FileSystemStorage):
  
-     def get_available_name(self, name):
+     def get_available_name(self, name, max_length=None):
          return name
  
      def _save(self, name, content):
          full_path = self.path(name)
          # make sure an existing file is replaced by removing the
          # original file first
          if os.path.exists(full_path):
              os.remove(full_path)
          return super(OverwriteStorage, self)._save(name, content)
  
  
Migrate to new Storage API
## Code Before:

import os.path
from django.core.files.storage import FileSystemStorage

class OverwriteStorage(FileSystemStorage):

    def get_available_name(self, name):
        return name

    def _save(self, name, content):
        full_path = self.path(name)
        # make sure an existing file is replaced by removing the
        # original file first
        if os.path.exists(full_path):
            os.remove(full_path)
        return super(OverwriteStorage, self)._save(name, content)


## Instruction:
Migrate to new Storage API
## Code After:

import os.path
from django.core.files.storage import FileSystemStorage

class OverwriteStorage(FileSystemStorage):

    def get_available_name(self, name, max_length=None):
        return name

    def _save(self, name, content):
        full_path = self.path(name)
        # make sure an existing file is replaced by removing the
        # original file first
        if os.path.exists(full_path):
            os.remove(full_path)
        return super(OverwriteStorage, self)._save(name, content)

