MCPcopy
hub / github.com/django/django / _earliest

Method _earliest

django/db/models/query.py:1140–1160  ·  view source on GitHub ↗

Return the earliest object according to fields (if given) or by the model's Meta.get_latest_by.

(self, *fields)

Source from the content-addressed store, hash-verified

1138 return params
1139
1140 def _earliest(self, *fields):
1141 """
1142 Return the earliest object according to fields (if given) or by the
1143 model's Meta.get_latest_by.
1144 """
1145 if fields:
1146 order_by = fields
1147 else:
1148 order_by = getattr(self.model._meta, "get_latest_by")
1149 if order_by and not isinstance(order_by, (tuple, list)):
1150 order_by = (order_by,)
1151 if order_by is None:
1152 raise ValueError(
1153 "earliest() and latest() require either fields as positional "
1154 "arguments or 'get_latest_by' in the model's Meta."
1155 )
1156 obj = self._chain()
1157 obj.query.set_limits(high=1)
1158 obj.query.clear_ordering(force=True)
1159 obj.query.add_ordering(*order_by)
1160 return obj.get()
1161
1162 def earliest(self, *fields):
1163 if self.query.is_sliced:

Callers 2

earliestMethod · 0.95
latestMethod · 0.80

Calls 5

_chainMethod · 0.95
set_limitsMethod · 0.80
clear_orderingMethod · 0.80
add_orderingMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected