MCPcopy
hub / github.com/django/django / only

Method only

django/db/models/query.py:1950–1969  ·  view source on GitHub ↗

Essentially, the opposite of defer(). Only the fields passed into this method and that are not already specified as deferred are loaded immediately when the queryset is evaluated.

(self, *fields)

Source from the content-addressed store, hash-verified

1948 return clone
1949
1950 def only(self, *fields):
1951 """
1952 Essentially, the opposite of defer(). Only the fields passed into this
1953 method and that are not already specified as deferred are loaded
1954 immediately when the queryset is evaluated.
1955 """
1956 self._not_support_combined_queries("only")
1957 if self._fields is not None:
1958 raise TypeError("Cannot call only() after .values() or .values_list()")
1959 if fields == (None,):
1960 # Can only pass None to defer(), not only(), as the rest option.
1961 # That won't stop people trying to do this, so let's be explicit.
1962 raise TypeError("Cannot pass None as an argument to only().")
1963 for field in fields:
1964 field = field.split(LOOKUP_SEP, 1)[0]
1965 if field in self.query._filtered_relations:
1966 raise ValueError("only() is not supported with FilteredRelation.")
1967 clone = self._chain()
1968 clone.query.add_immediate_loading(fields)
1969 return clone
1970
1971 def using(self, alias):
1972 """Select which database this QuerySet should execute against."""

Callers 15

queryset_iteratorMethod · 0.80
queryset_iteratorMethod · 0.80
refresh_from_dbMethod · 0.80
collectMethod · 0.80
get_querysetMethod · 0.80
get_querysetMethod · 0.80
test_custom_qsMethod · 0.80
test_deferred_modelsMethod · 0.80
test_ticket7235Method · 0.80
test_ticket22023Method · 0.80

Calls 4

_chainMethod · 0.95
add_immediate_loadingMethod · 0.80
splitMethod · 0.45