call the method n.getAttribute with string 'pk' as argument, use the result as an argument for the call to the field.rel.to._meta.pk.to_python method, substitute the result for obj_pk.
obj_pk = field . rel . to . _meta . pk . to_python ( n . getAttribute ( 'pk' ) )