Skip to content
  • Categories
  • Tags
  • Popular
  • Users
  • Groups
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (Flatly)
  • No Skin
Collapse

Odoo 中文社区

  1. Home
  2. Categories
  3. Odoo 培训
  4. Odoo的Binary字段如何保存文件名

Odoo的Binary字段如何保存文件名

Scheduled Pinned Locked Moved Odoo 培训
odoo技术binary field
1 Posts 1 Posters 1.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    digitalsatori
    管理员
    wrote on last edited by
    #1

    我们定义一个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"/>
    

    【上海先安科技】(tony AT openerp.cn)

    1 Reply Last reply
    0

    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
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Tags
    • Popular
    • Users
    • Groups