Fixed #26186 -- Documented how app relative relationships of abstract models behave.

This partially reverts commit bc7d201bdb.

Thanks Tim for the review.

Refs #25858.
This commit is contained in:
Simon Charette 2016-02-22 16:05:47 -05:00
parent eac1423f9e
commit 0223e213dd
4 changed files with 71 additions and 36 deletions

View file

@ -1157,6 +1157,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