[1.7.x] Fixed #24007 -- Ensure apps registry's ready before unpickling models

This prevents AppRegistryNotReady errors when unpickling Django
models from an external script.
Backport of 108b8bf85 from master.