MCPcopy
hub / github.com/django/django / first

Method first

django/db/models/query.py:1182–1190  ·  view source on GitHub ↗

Return the first object of a query or None if no match is found.

(self)

Source from the content-addressed store, hash-verified

1180 return await sync_to_async(self.latest)(*fields)
1181
1182 def first(self):
1183 """Return the first object of a query or None if no match is found."""
1184 if self.ordered or not self.query.default_ordering:
1185 queryset = self
1186 else:
1187 self._check_ordering_first_last_queryset_aggregation(method="first")
1188 queryset = self.order_by("pk")
1189 for obj in queryset[:1]:
1190 return obj
1191
1192 async def afirst(self):
1193 return await sync_to_async(self.first)()

Callers 15

get_latest_lastmodMethod · 0.80
shortcutFunction · 0.80
setUpClassMethod · 0.80
_testMethod · 0.80
test_empty_querysetMethod · 0.80
test_basicMethod · 0.80
test_ignores_nullMethod · 0.80
test_propagates_nullMethod · 0.80