code: def objectgetter(model, attr_name='pk', field_name='pk'):
      
      def _getter(request, *view_args, **view_kwargs):
          if attr_name not in view_kwargs:
              raise ImproperlyConfigured(
                  'Argument {0} is not available. Given arguments: [{1}]'
                  .format(attr_name, ', '.join(view_kwargs.keys())))
          try:
              return get_object_or_404(model, **{field_name: view_kwargs[attr_name]})
          except FieldError:
              raise ImproperlyConfigured(
                  'Model {0} has no field named {1}'
                  .format(model, field_name))
      return _getter
docs: 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.