[1.7.x] Use the new implementation of `six.with_metaclass`.

No more `NewBase` horrors.

Thanks to bendavis78 for his work on merging this into six.

Backport of a2340ac6d6 from master
[1.7.x] Fixed #22447 -- Make sure custom model bases can be migrated.

Thanks to cdestigter for the report.

Backport of 390f888745 from master