Limiting access to fields in models
In other circumstances, we may want additional fine-grained access control, as well as the ability to restrict access to individual fields in a model.
Using the groups
property, it is possible to restrict access to a field to certain security groups. This recipe will demonstrate how to add a field with restricted access to the Hostels model.
Getting ready
We will continue using the my_hostel
module from the previous tutorial.
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_hostel.group_hostel_manager') notes = fields.Text(groups='my_hostel.group_hostel_manager')
- Edit the view in the XML file to add the field:
<field name="is_public" /> <field name="notes" />
That’s it. Now, upgrade the add-on module for the changes...