MCPcopy
hub / github.com/django/django / last

Method last

django/db/models/query.py:1195–1203  ·  view source on GitHub ↗

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

(self)

Source from the content-addressed store, hash-verified

1193 return await sync_to_async(self.first)()
1194
1195 def last(self):
1196 """Return the last object of a query or None if no match is found."""
1197 if self.ordered or not self.query.default_ordering:
1198 queryset = self.reverse()
1199 else:
1200 self._check_ordering_first_last_queryset_aggregation(method="last")
1201 queryset = self.order_by("-pk")
1202 for obj in queryset[:1]:
1203 return obj
1204
1205 async def alast(self):
1206 return await sync_to_async(self.last)()

Calls 3

reverseMethod · 0.95
order_byMethod · 0.95