code: def _get_pk_value(self, instance):
          
          pk_field = instance._meta.pk.name
          pk = getattr(instance, pk_field, None)
  
          # Check to make sure that we got an pk not a model object.
          if isinstance(pk, models.Model):
              pk = self._get_pk_value(pk)
          return pk
docs: Get the primary key field value for a model instance.
  
          :param instance: The model instance to get the primary key for.
          :type instance: Model
          :return: The primary key value of the given model instance.