Changing the user that performs an action
When writing business logic code, you may have to perform some actions with a different security context. A typical case is performing an action with superuser
rights, bypassing security checks. Such a requirement arises when business requirements necessitate operating on records for which users do not have security access rights.
This recipe will show you how to allow normal users to create the room
record by using sudo()
. Put simply, we will allow users to create room
by themselves, even if they do not have the right to create a assign the room
record.
Getting ready
For easier understanding, we will add a new model to manage the hostel room. We will add a new model called hostel.student
. You can refer to the following definition to add this model:
class HostelStudent(models.Model): _name = "hostel.student" _description = "Hostel Student Information" name...