소스 검색

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

Thanks simonpercivall for the report and Aymeric for the patch.
Tim Graham 11 년 전
부모
커밋
5c7ac7494a
1개의 변경된 파일10개의 추가작업 그리고 5개의 파일을 삭제
  1. 10 5
      docs/topics/db/queries.txt

+ 10 - 5
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
-domain.
+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
 ----------------------------