İçereği Atla
Menü
Bu soru işaretlendi
2 Cevaplar
23417 Görünümler

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...

Avatar
Vazgeç

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

En İyi Yanıt

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>
Avatar
Vazgeç

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.

En İyi Yanıt

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

Avatar
Vazgeç
İlgili Gönderiler Cevaplar Görünümler Aktivite
4
Mar 22
17225
2
Ara 21
1779
0
Eki 21
2882
3
Kas 24
14009
0
Haz 22
2365