diff options
| author | Simon Charette <charette.s@gmail.com> | 2016-02-22 16:05:47 -0500 |
|---|---|---|
| committer | Simon Charette <charette.s@gmail.com> | 2016-02-29 22:13:54 -0500 |
| commit | 48cf7516409c668bf11e24e6b7cd8eaea13ae3b8 (patch) | |
| tree | 5b4c48da5e86dcf2cf6412fde0ce67dff01147fa /docs/ref | |
| parent | e9234569f69e0afcc97b3b1ff5293bad1678a076 (diff) | |
[1.9.x] Fixed #26186 -- Documented how app relative relationships of abstract models behave.
This partially reverts commit bc7d201bdbaeac14a49f51a9ef292d6312b4c45e.
Thanks Tim for the review.
Refs #25858.
Backport of 0223e213dd690b6b6e0669f836a20efb10998c83 from master
Diffstat (limited to 'docs/ref')
| -rw-r--r-- | docs/ref/models/fields.txt | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/docs/ref/models/fields.txt b/docs/ref/models/fields.txt index d8d047e3c9..20c50a0b12 100644 --- a/docs/ref/models/fields.txt +++ b/docs/ref/models/fields.txt @@ -1155,6 +1155,35 @@ you can use the name of the model, rather than the model object itself:: # ... pass +Relationships defined this way on :ref:`abstract models +<abstract-base-classes>` are resolved when the model is subclassed as a +concrete model and are not relative to the abstract model's ``app_label``: + +.. snippet:: + :filename: products/models.py + + from django.db import models + + class AbstractCar(models.Model): + manufacturer = models.ForeignKey('Manufacturer', on_delete=models.CASCADE) + + class Meta: + abstract = True + +.. snippet:: + :filename: production/models.py + + from django.db import models + from products.models import AbstractCar + + class Manufacturer(models.Model): + pass + + class Car(AbstractCar): + pass + + # Car.manufacturer will point to `production.Manufacturer` here. + To refer to models defined in another application, you can explicitly specify a model with the full application label. For example, if the ``Manufacturer`` model above is defined in another application called ``production``, you'd |
