I need a form which accept upload android .apk file. and download it with same name.
Here is what I start with
# model.py
class AppVersion(models.Model):
# ...
apk_file = fields.Binary('Apk file', filters='*.apk', required=True)
But in odoo-14 the filters
param is not work any more. It accept all kind files.
And after upload complete, download button gives me a zip file.
After some source code research I found the solution:
Add a options
attribute with accepted_file_extensions
property into the binary field.
Add a new char field in model to save the file name, bind it to binary field with filename
attribute. and don't forget add the new field into form view (set to invisible
)
# model
class AppVersion(models.Model):
# ...
apk_file = fields.Binary('Apk file', store=True, attachment=False, required=True)
apk_fname = fields.Char(string='File name')
<!--form view-->
<field name="apk_file" widget="binary" options="{'accepted_file_extensions': '.apk'}" filename="apk_fname"/>
<field name="apk_fname" invisible="1"/>