-
-
Save imgVOID/9e010faf058b0de8ce539dab6efe018f to your computer and use it in GitHub Desktop.
Поле отношения ForeignKey
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
class ModelA(models.Model): | |
name = models.CharField() | |
class ModelB(models.Model): | |
a = models.ForeignKey(ModelA) | |
# "Прямое" поле отношения ForeignKey: | |
ModelB.objects.select_related('a').all() | |
# "Обратное" поле отношения ForeignKey: | |
ModelA.objects.prefetch_related('modelb_set').all() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment