I'm working on a Django project and trying to figure out how I can test for user ownership and allow editing or redirect based on the result.
I have a model Scene
. Scene
is linked to User
to track which user created a particular Scene
:
class Scene(models.Model):
user = models.ForeignKey(User)
[rest of Scene model]
I have a URL pattern to edit a particular Scene
object like this:
url(r'^scenes/(?P<pk>[0-9]+)/edit/', SceneUpdateView.as_view(), name='scene-edit'),
I have a logged in user via django-allauth. I want only Scene
owners to be able to edit Scenes
.
I'm trying to figure out how to use a decorator to test if scene.user.id == self.request.user.id
for the particular scene called by the URL.
Do I need to send URL information into permission_required
or user_passes_test
decorators (is this possible)?
How can I make this happen?