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)
| 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 | """ |