The flange in question is the black tab on the left seen most clearly in the second photo. On third party lenses these are sometimes too long and prevent the lens from being locked in place or interfering the diaphragm stop down lever on the camera.
However it looks to me as though the diaphragm stop down lever on the lens has been filed down. Canon users will often mangle this part as it can strike the mirror or other parts in Canon DSLRs. It may be too short to reach the lever in the camera.
This lens does not appear to have an "A" setting on it. You probably need to enable the use of aperture ring in your setup and use stop-down metering. Does it stop down when you make an exposure?
https://www.pentaxforums.com/forums/pentax-lens-articles/110657-how-use-meter...k-x-k-7-a.html
If this doesn't work:
When mounting the lens does it turn far enough that the locking pin engages? If it doesn't the flange may be the problem.
If the lens locks in place is the aperture always fully closed? If so the lever is probably too short. If this is the case you'll have to repair the lever somehow.