Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
2 Răspunsuri
23580 Vizualizări

How can I use urls instead of binary data for the product images? Or, if not possible, how to use the filesystem instead of the database for product images?

I know how to do it with attachments, but how does it work with product images?

Thanks for any proper answer...

Imagine profil
Abandonează

did you meant to get an image from a url entered and show in binary field?

Cel mai bun răspuns

if you meant to get an image from a given url: the python code and xml is as follows: python:

import base64#file encode
import urllib2 #file download from url

class image_url(osv.osv):
    _name="image.url"
    _columns={
               'image':fields.binary('Image',frequired=True),
               'web':fields.char('image url', help='Automatically sanitized HTML contents'),
                        }
    def onchange_image(self,cr,uid,ids,web,context=None):
        link=web
        photo = base64.encodestring(urllib2.urlopen(link).read())
        val={
             'image':photo,
             }
        return {'value': val}
 image_url()

xml view:

<record id="view_mrk_form" model="ir.ui.view">
            <field name="name">mark.marksheet.form</field>
            <field name="model">mark.marksheet</field>
            <field name="arch" type="xml">
            <form string="image">
                 <field name="image" widget="image" width="110" height="70" />
                 <field name="web" widget="url" on_change="onchange_image(web,context)"/>
            </form>
            </field>
</record>
Imagine profil
Abandonează

Perfect..Thank You so much.. It helped a lot.

@Chandni, thank you for your detailed explanation. Do you have a github repository that I can fork this module from? I would like to include it as a dependency in an open-source theme module i'm building and would like to make sure I accredit you correctly.

Cel mai bun răspuns

You have to check the link option and indicate your file location.

Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
4
mar. 22
17404
2
dec. 21
1839
0
oct. 21
2994
3
nov. 24
14248
0
iun. 22
2458