code: def get_object_from_classbased_instance(
          instance, queryset, request, *args, **kwargs):
      
      from django.views.generic.edit import BaseCreateView
      # initialize request, args, kwargs of classbased_instance
      # most of methods of classbased view assumed these attributes
      # but these attributes is initialized in ``dispatch`` method.
      instance.request = request
      instance.args = args
      instance.kwargs = kwargs
  
      # get queryset from class if ``queryset_or_model`` is not specified
      if hasattr(instance, 'get_queryset') and not queryset:
          queryset = instance.get_queryset()
      elif hasattr(instance, 'queryset') and not queryset:
          queryset = instance.queryset
      elif hasattr(instance, 'model') and not queryset:
          queryset = instance.model._default_manager.all()
  
      # get object
      if hasattr(instance, 'get_object'):
          try:
              obj = instance.get_object(queryset)
          except AttributeError as e:
              # CreateView has ``get_object`` method but CreateView
              # should not have any object before thus simply set
              # None
              if isinstance(instance, BaseCreateView):
                  obj = None
              else:
                  raise e
      elif hasattr(instance, 'object'):
          obj = instance.object
      else:
          obj = None
      return obj
docs: Get object from an instance of classbased generic view
  
      Parameters
      ----------
      instance : instance
          An instance of classbased generic view
      queryset : instance
          A queryset instance
      request : instance
          A instance of HttpRequest
  
      Returns
      -------
      instance
          An instance of model object or None