1👍
✅
Typically, (using class based views), I’ll handle this in the get_queryset
method so it would be something like
class PropertyDetail(DetailView):
def get_queryset(self):
return self.request.user.property_set.all()
and that will give a 404 if the property isn’t for the current user. You might prefer to use a project like django-guardian if you end up with more permission relationships than just Property
.
If you take a look at UserPassesTestMixin you’ll see that it processes the test_func
before calling dispatch
so you’ll have to call self.get_object(request)
yourself if you decide to go that route.
Source:stackexchange.com