We study the Lagrangian properties of the discrete isospectral and isomonodromic dynamical systems. We generalize the Moser-Veselov approach to integrability of discrete isospectral systems via the refactorization of matrix polynomials to matrix rational functions with a simple divisor, and consider in detail the case of two poles or, equivalently, of two elementary factors. In this case, we establish, by explicitly writing down the Lagrangian, that the isomonodromic dynamic is Lagrangian. Next, we show how to make this Lagrangian time dependent to obtain the equations of the isomonodromic dynamic. In some special cases, such equations are known to reduce to the difference Painlevé equations. We show how to obtain the difference Painlevé V equation in that way, establishing that dPV can be written in the Lagrangian form.