This was fixed earlier but only when the M2M relation was at the first
level on the object. This commit fixes the issue even when the M2M is
at deeper levels, such as behind a foreign key.
Before this change, the get_admin_log method would expect User model's
FK to be named `id`. When changing that FK name, admin/index.html
rendering would fail.
This includes:
* Changed the use of id for the use of pk property.
* Added a regression test that fails without the patch.
This commit refs #20088.