Return the first object of a query or None if no match is found.
(self)
| 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)() |