Trợ giúp

1

How do I save a file (image or pdf) to a model?

Avatar
Levi Bensley

Hello,

I am  making a custom module to store data on custom tools which require a pdf, image or design file to be saved in with the tools model and Im not sure on how to implement this?

I guesses I could possibly use ir.attachment but not sure on how to implement it.

Thanks for any help  

1 Bình luận
Ảnh đại diện
Huỷ bỏ
Avatar
Sehrish
-

By using binary fields: https://goo.gl/2JAxhD

2 Câu trả lời
1
Avatar
Paresh Wagh
Best Answer

Hi Levi: You also have the option of defining the field as a binary (odoo.fields.Binary) field. Attachments provide you the ability to attach multiple documents. The binary field will allow you to store one document in the binary field.

Ảnh đại diện
Huỷ bỏ
1
Avatar
Niyas Raphy
Best Answer

Hi,

See the below samples of adding Many2one and Many2Many field for storing files.

attachment_id = fields.Many2one('ir.attachment', string='Attachment', ondelete='cascade')

doc_attachment_id = fields.Many2many('ir.attachment', 'doc_attach_rel', 'doc_id', 'attach_id3', string="Attachment",
help='You can attach the copy of your document', copy=False)


Thanks

Ảnh đại diện
Huỷ bỏ