summaryrefslogtreecommitdiff
path: root/docs/ref
diff options
context:
space:
mode:
authorKevin Christopher Henry <k@severian.com>2016-08-11 04:59:19 -0400
committerTim Graham <timograham@gmail.com>2016-08-17 10:35:29 -0400
commit3db01b2d5824a885871502a940901e8e83c73fde (patch)
tree09ffec9a5a2ed7edf8aea2d37e3bdca73bc9e686 /docs/ref
parentf6af24fe4007d5eb52c919c2db5d493de06080d8 (diff)
[1.10.x] Fixed #26616 -- Clarified model usage in AppConfig.ready().
Backport of ff445f4c19a0fdf6696c99efefa38b1409b8709f from master
Diffstat (limited to 'docs/ref')
-rw-r--r--docs/ref/applications.txt20
1 files changed, 17 insertions, 3 deletions
diff --git a/docs/ref/applications.txt b/docs/ref/applications.txt
index d1183ce4bf..2340951542 100644
--- a/docs/ref/applications.txt
+++ b/docs/ref/applications.txt
@@ -239,13 +239,27 @@ Methods
as registering signals. It is called as soon as the registry is fully
populated.
- You cannot import models in modules that define application configuration
- classes, but you can use :meth:`get_model` to access a model class by
- name, like this::
+ Although you can't import models at the module-level where
+ :class:`~django.apps.AppConfig` classes are defined, you can import them in
+ ``ready()``, using either an ``import`` statement or
+ :meth:`~AppConfig.get_model`.
+
+ If you're registering :mod:`model signals <django.db.models.signals>`, you
+ can refer to the sender by its string label instead of using the model
+ class itself.
+
+ Example::
+
+ from django.db.models.signals import pre_save
def ready(self):
+ # importing model classes
+ from .models import MyModel # or...
MyModel = self.get_model('MyModel')
+ # registering signals with the model's string label
+ pre_save.connect(receiver, sender='app_label.MyModel')
+
.. warning::
Although you can access model classes as described above, avoid