Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odpovědět
23322 Zobrazení

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?

Avatar
Zrušit
Nejlepší odpověď

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

Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
3
úno 25
3539
0
kvě 24
46
1
dub 24
3347
4
zář 23
4830
2
zář 23
7043