From the course: Securing Django Applications

Unlock the full course today

Join today to access over 22,700 courses taught by industry experts or purchase this course individually.

Enabling per-object permissions in Django

Enabling per-object permissions in Django - Django Tutorial

From the course: Securing Django Applications

Start my 1-month free trial

Enabling per-object permissions in Django

- [Instructor] Now that we have per object permissions enabled we need to assign permissions to model whenever a user creates it. When a user books a tour package, a booking model instance is created. It is logical that the user is the only one that can modify their own booking. So we're going to start by importing the receiver decorator. And then we're going to be importing the post save signal. And from guardian, we are going to be importing the shortcut for assigning permission. Now we scroll down to after the booking model definition and we're going to be using the receiver and we are going to be acting on the post save signal, for the booking and we call it set booking permissions. And the user is based on the email address of the booking. And we're going to assign permission for the API change booking permission. We're going to assign it to the user and that's the model level permission. And now we're…

Contents