This function could use tests. Those would also help explain what this does and what to expect from it.

There are several test projects in the top-level tests module, each with apps and models already defined, so you could just add tests to an existing test project.