from django.utils.functional import wraps ... def check_company_admin(view): @wraps(view) def inner(request, slug, *args, **kwargs): # Get the company object company = get_object_or_404(Company, slug=slug) # Check and see if the logged in user is admin if company.admin_user != request.user: return HttpResponseForbidden() # Return the actual company object to the view return view(request, company, *args, **kwargs) return inner