diff options
| author | Clifford Gama <cliffygamy@gmail.com> | 2025-01-13 21:15:57 +0200 |
|---|---|---|
| committer | Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> | 2025-03-21 14:10:47 +0100 |
| commit | 37b8a45f5a7260ecaec851c9f359240a7d15afbb (patch) | |
| tree | f7dc6665c27cb1391be45b71501598b0f4553e2d /docs/topics | |
| parent | 61535d2228bc1dec5d843793f1c1cfe27a784acc (diff) | |
[5.2.x] Fixed #36095 -- Introduced lazy references in "Models across files" section.
Backport of 6a2c296e706a0b8f9f9b89e66b37001ce2a03ea7 from main.
Diffstat (limited to 'docs/topics')
| -rw-r--r-- | docs/topics/db/models.txt | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/docs/topics/db/models.txt b/docs/topics/db/models.txt index b7bd36bc81..98fb149b98 100644 --- a/docs/topics/db/models.txt +++ b/docs/topics/db/models.txt @@ -720,6 +720,24 @@ refer to the other model class wherever needed. For example:: 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 ----------------------- |
