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')
@classmethod
def convert_photo(cls, data):
    if data and Image:
        image = Image.open(BytesIO(data))
        image.thumbnail((200, 200), Image.ANTIALIAS)
        data = BytesIO()
        image.save(data, 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

@classmethod
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

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

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