Painting on separate objects with one material applied on all of them?

Is there a way to paint on the board without the paint affecting the pole ? (picture example: I need red paint only to apply on the ‘‘board’’ but not on the “pole”(yellow area)

like isolating areas I don’t want the paint to apply on