Forward porting of #1128 by @kezabelle. Still some tests failing.
Change allowed query numbers in AdminFormsTests and GlobalPermissionTests
Yet another query number adjustment
Fix tests when custom user model is used
Merge pull request #2701 from yakky/feature/forwardport_1128

Forward porting of #1128