def delete_orphaned_document_files():
 documents_path = os.path.join(settings.MEDIA_ROOT, 'documents')
 for filename in os.listdir(documents_path):
  fn = os.path.join(documents_path, filename)
  if (Document.objects.filter(doc_file__contains=filename).count() == 0):
   print ('Removing orphan document %s' % fn)
   try:
    os.remove(fn)
   except OSError:
    print ('Could not delete file %s' % fn)

def delete_orphaned_document_files ( ) : documents_path = os . path . join ( settings . MEDIA_ROOT , 'documents' ) for filename in os . listdir ( documents_path ) : fn = os . path . join ( documents_path , filename ) if ( Document . objects . filter ( doc_file__contains = filename ) . count ( ) == 0 ) : print ( 'Removing orphan document %s' % fn ) try : os . remove ( fn ) except OSError : print ( 'Could not delete file %s' % fn )
deletes orphaned files of deleted documents .