mirror of
https://github.com/django/django.git
synced 2025-06-03 18:49:12 +00:00
Fixed #36095 -- Introduced lazy references in "Models across files" section.
This commit is contained in:
parent
eb4ea9c3ef
commit
6a2c296e70
@ -720,6 +720,24 @@ refer to the other model class wherever needed. For example::
|
|||||||
null=True,
|
null=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Alternatively, you can use a lazy reference to the related model, specified as
|
||||||
|
a string in the format ``"app_label.ModelName"``. This does not require the
|
||||||
|
related model to be imported. For example::
|
||||||
|
|
||||||
|
from django.db import models
|
||||||
|
|
||||||
|
|
||||||
|
class Restaurant(models.Model):
|
||||||
|
# ...
|
||||||
|
zip_code = models.ForeignKey(
|
||||||
|
"geography.ZipCode",
|
||||||
|
on_delete=models.SET_NULL,
|
||||||
|
blank=True,
|
||||||
|
null=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
See :ref:`lazy relationships <lazy-relationships>` for more details.
|
||||||
|
|
||||||
Field name restrictions
|
Field name restrictions
|
||||||
-----------------------
|
-----------------------
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user