Odoo的Binary字段如何保存文件名
-
我们定义一个
fields.Binary类型的字段就可以上传文件并保存。但是,这仅仅保存了文件的内容,下载时的文件的名称为该模型的名称而不是原上传文件的文件名。我们在代码中也无法引用该上传文件的文件名。那我们如何才能做到既保存上传文件的文件内容又保存其文件名呢?首先, 我们要另外定义一个保存文件名的字符字段,比如
test_img = fields.Binary('Test Image') test_img_file_name = fields.Char('File name')然后在视图中跟Binary字段做关联:
<field name="test_img" filename="test_img_file_name"/> <field name="test_img_file_name" invisible="1"/>
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login