Renamed QuerySet.earliest()/latest() helper method.

This commit is contained in:
Tim Graham 2018-12-30 11:43:39 -05:00 committed by GitHub
parent bdf3863bdd
commit 100b8dd163
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 5 deletions

View File

@ -607,10 +607,10 @@ class QuerySet:
))
return params
def _earliest_or_latest(self, *fields, field_name=None):
def _earliest(self, *fields, field_name=None):
"""
Return the latest object, according to the model's
'get_latest_by' option or optional given field_name.
Return the earliest object according to fields (if given) or by the
model's Meta.get_latest_by.
"""
if fields and field_name is not None:
raise ValueError('Cannot use both positional arguments and the field_name keyword argument.')
@ -643,10 +643,10 @@ class QuerySet:
return obj.get()
def earliest(self, *fields, field_name=None):
return self._earliest_or_latest(*fields, field_name=field_name)
return self._earliest(*fields, field_name=field_name)
def latest(self, *fields, field_name=None):
return self.reverse()._earliest_or_latest(*fields, field_name=field_name)
return self.reverse()._earliest(*fields, field_name=field_name)
def first(self):
"""Return the first object of a query or None if no match is found."""