By using the
attrs attribute on a view element you can dynamically set its attributes based on another field’s value. For example you could make a field
long_description read-only provided that
short_description is not filled out:
…or present the user with a special message based on field’s value:
As you may have noticed,
Recently I wanted to make an item invisible when many2many relation is empty:
“I like those too!” should appear only after at least one pony was added to the pony_ids many2many relation.
I wasn’t sure about the exact form the domain should take. I begun by trying those:
[('pony_ids', '=', False)]
[('pony_ids', '=', None)]
[('pony_ids', '=', )]
To no avail.
At the end it turned out (thank you Chrome Developer Tools!) that the domain should be
[('pony_ids', '=', [(6, False, )])]:
This of course brings to mind the three-element tuple commands (I also described them here). Note however that you need to use the exact form I showed above. Looking at the commands documentation, you may think that version with
4 instead or
None instead of
If you want a domain that matches a many2many relation with a particular set of objects you can, but remember that the order also have to match. Here’s an example of a domain matching a relation with one pony with id
[('pony_ids', '=', [(6, False, )])].