Limiting access to fields in models
In some cases, we may need more fine-grained access control, and we may also need to limit access to specific fields in a model.
It is possible for a field to only be accessed by specific security groups, using the groups
attribute. In this recipe, we will show you how to add a field with limited access to the Library Books model.
Getting ready
We will continue using the my_library
module from the previous recipe.
How to do it...
To add a field with access that's limited to specific security groups, perform the following steps:
- Edit the model file to add the field:
is_public = fields.Boolean(groups='my_library.group_library_librarian') private_notes = fields.Text(groups='my_library.group_library_librarian')
- Edit the view in the XML file to add the field:
<field name="is_public" /> <field name="private_notes" />
That's it. Now, upgrade the add-on module...