code: def redirect(post_save_redirect, obj):
      
      if post_save_redirect:
          return HttpResponseRedirect(post_save_redirect % obj.__dict__)
      elif hasattr(obj, 'get_absolute_url'):
          return HttpResponseRedirect(obj.get_absolute_url())
      else:
          raise ImproperlyConfigured(
              "No URL to redirect to.  Either pass a post_save_redirect"
              " parameter to the generic view or define a get_absolute_url"
              " method on the Model.")
docs: Returns a HttpResponseRedirect to ``post_save_redirect``.
  
      ``post_save_redirect`` should be a string, and can contain named string-
      substitution place holders of ``obj`` field names.
  
      If ``post_save_redirect`` is None, then redirect to ``obj``'s URL returned
      by ``get_absolute_url()``.  If ``obj`` has no ``get_absolute_url`` method,
      then raise ImproperlyConfigured.
  
      This function is meant to handle the post_save_redirect parameter to the
      ``create_object`` and ``update_object`` views.