[1.7.x] Fixed #23616 - Fixed generic relations in ModelAdmin.list_filter.

Thanks ranjur for reporting bug, timgraham for review,
and collinanderson for contributing tips.

Backport of 06b11b617e from master