Default binary field value

I have to display a set of images for the client to use them as a reference.
I have tried using fields.Binary() and wrote a class method as below

photo = fields.Binary('phtoto')
def convert_photo(cls, data):
    if data and Image:
        image =
        image.thumbnail((200, 200), Image.ANTIALIAS)
        data = BytesIO(), image.format)
        data = fields.Binary.cast(data.getvalue())
    return data

Now, this works well if I want to upload an image and display.

How do I give a default Binary image and display it to the client?

Do I have to give a default method, if so how, with an example. Else any other better way to do it

Thank you.
Have a nice day

Define default value is described in Default value of fields — trytond 5.3 documentation

yes. That was what I would do for Date field , Integer and so on.
Since I have,say ‘picture.jpg’ with me in my local system. How do I give it as default return value

def default_photo(cls):
    return value

how should I return ‘picture.jpg’ in value?

You have to read the content from the file and return it as default value.

Thank You for your valuable input.
I could return the picture as default value with the following code

def default_photo(cls):
    path = "img/test.png"
    file_ = open(path, "rb")

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.