diff options
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 |
