MCPcopy
hub / github.com/django/django / select_related

Method select_related

django/db/models/query.py:1756–1786  ·  view source on GitHub ↗

Return a new QuerySet instance that will select related objects. If fields are specified, they must be ForeignKey fields and only those related objects are included in the selection. If select_related(None) is called, clear the list.

(self, *fields)

Source from the content-addressed store, hash-verified

1754 return obj
1755
1756 def select_related(self, *fields):
1757 """
1758 Return a new QuerySet instance that will select related objects.
1759
1760 If fields are specified, they must be ForeignKey fields and only those
1761 related objects are included in the selection.
1762
1763 If select_related(None) is called, clear the list.
1764 """
1765 self._not_support_combined_queries("select_related")
1766 if self._fields is not None:
1767 raise TypeError(
1768 "Cannot call select_related() after .values() or .values_list()"
1769 )
1770
1771 obj = self._chain()
1772 if fields == (None,):
1773 obj.query.select_related = False
1774 elif fields:
1775 obj.query.add_select_related(fields)
1776 else:
1777 # RemovedInDjango70Warning: when the deprecation ends, raise a
1778 # TypeError instead.
1779 warnings.warn(
1780 "Calling select_related() with no arguments is deprecated. "
1781 "Specify the fields to fetch instead.",
1782 category=RemovedInDjango70Warning,
1783 skip_file_prefixes=django_file_prefixes(),
1784 )
1785 obj.query.select_related = True
1786 return obj
1787
1788 def prefetch_related(self, *lookups):
1789 """

Callers 15

__init__Method · 0.80
get_log_entriesMethod · 0.80
history_viewMethod · 0.80
related_objectsMethod · 0.80
apply_select_relatedMethod · 0.80
queryset_iteratorMethod · 0.80
queryset_iteratorMethod · 0.80
test_null_fkMethod · 0.80

Calls 4

_chainMethod · 0.95
django_file_prefixesFunction · 0.90
add_select_relatedMethod · 0.80