Skip to content

Instantly share code, notes, and snippets.

@maxmumford
Last active August 29, 2015 13:57
Show Gist options
  • Save maxmumford/9371147 to your computer and use it in GitHub Desktop.
Save maxmumford/9371147 to your computer and use it in GitHub Desktop.
import base64
from osv import osv, fields
class my_class(osv.osv_memory):
def get_file(self, cr, uid, ids, field_name=None, arg=None, context=None):
result = dict.fromkeys(ids)
for record_browse in self.browse(cr, uid, ids):
f = open(record_browse.file_path)
result[record_browse.id] = base64.encodestring(f.read())
f.close()
return result
_name = 'my.class'
_columns = {
'file_path': fields.char('File Location', size=128),
'file': fields.function(get_file, method=True, store=False, type='binary', string="Download File"),
}
my_class()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment