Skip to content
Browse files

Fixed #18907 -- Correct docs regard population of model backrefs.

Thanks simonpercivall for the report and Aymeric for the patch.
  • Loading branch information...
1 parent 66f546b commit 5c7ac7494ab5f1cdc364f829f61ffef85ad7344b @timgraham timgraham committed
Showing with 10 additions and 5 deletions.
  1. +10 −5 docs/topics/db/queries.txt
15 docs/topics/db/queries.txt
@@ -1280,11 +1280,16 @@ relationship on one end.
But how is this possible, given that a model class doesn't know which other
model classes are related to it until those other model classes are loaded?
-The answer lies in the :setting:`INSTALLED_APPS` setting. The first time any
-model is loaded, Django iterates over every model in :setting:`INSTALLED_APPS`
-and creates the backward relationships in memory as needed. Essentially, one of
-the functions of :setting:`INSTALLED_APPS` is to tell Django the entire model
+The answer lies in the :data:`app registry <django.apps.apps>`. When Django
+starts, it imports each application listed in :setting:`INSTALLED_APPS`, and
+then the ``models`` module inside each application. Whenever a new model class
+is created, Django adds backward-relationships to any related models. If the
+related models haven't been imported yet, Django keeps tracks of the
+relationships and adds them when the related models eventually are imported.
+For this reason, it's particularly important that all the models you're using
+be defined in applications listed in :setting:`INSTALLED_APPS`. Otherwise,
+backwards relations may not work properly.
Queries over related objects

0 comments on commit 5c7ac74

Please sign in to comment.
Something went wrong with that request. Please try again.