[1.7.x] Added a unit test to ensure models cannot be ordered by a M2M field.

Backport of 865bc71783 from master