def objectgetter(model, attr_name='<STR_LIT>', field_name='<STR_LIT>'):
def _getter(request, *view_args, **view_kwargs):<EOL><INDENT>if attr_name not in view_kwargs:<EOL><INDENT>raise ImproperlyConfigured(<EOL>'<STR_LIT>'<EOL>.format(attr_name, '<STR_LIT:U+002CU+0020>'.join(view_kwargs.keys())))<EOL><DEDENT>try:<EOL><INDENT>return get_object_or_404(model, **{field_name: view_kwargs[attr_name]})<EOL><DEDENT>except FieldError:<EOL><INDENT>raise ImproperlyConfigured(<EOL>'<STR_LIT>'<EOL>.format(model, field_name))<EOL><DEDENT><DEDENT>return _getter<EOL>
Helper that returns a function suitable for use as the ``fn`` argument
to the ``permission_required`` decorator. Internally uses
``get_object_or_404``, so keep in mind that this may raise ``Http404``.

``model`` can be a model class, manager or queryset.

``attr_name`` is the name of the view attribute.

``field_name`` is the model's field name by which the lookup is made, eg.
"id", "slug", etc.