be sure that the ground for 12V is connect to the ground for the Raspberry PI 5V.
Looks like that relay has the same ground to activate the coil and activate the opto-coupler.
If you are using python , just use the gpio interface to activate the relay. The magnetic lock will be on the other side of the relay. Maybe a 5V coil relay will be better . You won't have to bring 12V near the raspberry PI and could be completely isolated .
With a 5V relay the power could be provided with the raspberry Pi. I assume that the power supply is strong enough.
http://www.dx.com/p/diy-5v-relay-isolat ... #.VKGa3sAA