تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
1 الرد
23299 أدوات العرض

gentextfile = fields.Binary(string='Text File')


file = open("sampletext.txt", 'w')

file.write("Hello World")

file.close()


How can I save it to the Binary Field declared?

الصورة الرمزية
إهمال
أفضل إجابة

Hello Dee Yoj,

Please check below code. I hope it will work.

E.g: 

Take two fields in .py file like below:

       import base64

        name : fields.Char(string='Name', size=64)

        gentextfile : fields.Binary('Click On Save As Button To Download File', readonly=True)

In .xml file:

                    <group>

                        <field name="name" invisible="1" />

                        <field name="gentextfile" filename="name"/>

                    </group>

write or Save your .txt file in binary field:

        file = open("sampletext.txt", "rb")

        out = file.read()

        file.close()

        gentextfile = base64.b64encode(out)

        name = 'sampletext.txt'

        OR

         record_set.write({'gentextfile': base64.b64encode(out), 'name': 'sampletext.txt'})

Thanks

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
3
فبراير 25
3489
0
مايو 24
46
1
أبريل 24
3325
4
سبتمبر 23
4810
2
سبتمبر 23
7028