Long text interception part of odoo tree view display problem

odoo's tree view field does not have the function of shortening long text, and it will be ugly when displaying long text. The following provides a method to achieve this function alternatively.
Suppose there is a longer text field named: description, we add a field named: display_description to the model

display_description= fields.Char(string='Description', compute='_compute_display_description')

@api.depends('description')
@api.onchange('description')
def _compute_display_description(self):
     for rec in self:
         rec.display_description= (rec.description[:10] + '...') if len(rec.description) > 20 else rec.description

The above means that the text length exceeds 20, then intercept the first 10 characters and add "..."
in the tree view, hide the description field and display the display_description field, or you can modify the number of words displayed by yourself.
for reference only.

Guess you like

Origin blog.csdn.net/weixin_42464956/article/details/110423014