Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
1fecde6b
Kaydet (Commit)
1fecde6b
authored
Ara 28, 2018
tarafından
Tim Graham
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Refs #11557 -- Removed the field_name keyword argument to QuerySet.earliest() and latest().
Per deprecation timeline.
üst
da5eb3d5
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
9 additions
and
37 deletions
+9
-37
query.py
django/db/models/query.py
+6
-17
3.0.txt
docs/releases/3.0.txt
+3
-0
tests.py
tests/get_earliest_or_latest/tests.py
+0
-20
No files found.
django/db/models/query.py
Dosyayı görüntüle @
1fecde6b
...
...
@@ -25,7 +25,6 @@ from django.db.models.query_utils import FilteredRelation, InvalidQuery, Q
from
django.db.models.sql.constants
import
CURSOR
,
GET_ITERATOR_CHUNK_SIZE
from
django.db.utils
import
NotSupportedError
from
django.utils
import
timezone
from
django.utils.deprecation
import
RemovedInDjango30Warning
from
django.utils.functional
import
cached_property
,
partition
from
django.utils.version
import
get_version
...
...
@@ -607,22 +606,12 @@ class QuerySet:
))
return
params
def
_earliest
(
self
,
*
fields
,
field_name
=
None
):
def
_earliest
(
self
,
*
fields
):
"""
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.'
)
if
field_name
is
not
None
:
warnings
.
warn
(
'The field_name keyword argument to earliest() and latest() '
'is deprecated in favor of passing positional arguments.'
,
RemovedInDjango30Warning
,
)
order_by
=
(
field_name
,)
elif
fields
:
if
fields
:
order_by
=
fields
else
:
order_by
=
getattr
(
self
.
model
.
_meta
,
'get_latest_by'
)
...
...
@@ -642,11 +631,11 @@ class QuerySet:
obj
.
query
.
add_ordering
(
*
order_by
)
return
obj
.
get
()
def
earliest
(
self
,
*
fields
,
field_name
=
None
):
return
self
.
_earliest
(
*
fields
,
field_name
=
field_name
)
def
earliest
(
self
,
*
fields
):
return
self
.
_earliest
(
*
fields
)
def
latest
(
self
,
*
fields
,
field_name
=
None
):
return
self
.
reverse
()
.
_earliest
(
*
fields
,
field_name
=
field_name
)
def
latest
(
self
,
*
fields
):
return
self
.
reverse
()
.
_earliest
(
*
fields
)
def
first
(
self
):
"""Return the first object of a query or None if no match is found."""
...
...
docs/releases/3.0.txt
Dosyayı görüntüle @
1fecde6b
...
...
@@ -247,6 +247,9 @@ to remove usage of these features.
* Support for the ``context`` argument of ``Field.from_db_value()`` and
``Expression.convert_value()`` is removed.
* The ``field_name`` keyword argument of ``QuerySet.earliest()` and
``latest()`` is removed.
See :ref:`deprecated-features-2.1` for details on these changes, including how
to remove usage of these features.
...
...
tests/get_earliest_or_latest/tests.py
Dosyayı görüntüle @
1fecde6b
from
datetime
import
datetime
from
django.test
import
TestCase
from
django.utils.deprecation
import
RemovedInDjango30Warning
from
.models
import
Article
,
IndexErrorArticle
,
Person
...
...
@@ -82,11 +81,6 @@ class EarliestOrLatestTests(TestCase):
Article
.
objects
.
model
.
_meta
.
get_latest_by
=
(
'pub_date'
,
'expire_date'
)
self
.
assertEqual
(
Article
.
objects
.
filter
(
pub_date
=
datetime
(
2005
,
7
,
28
))
.
earliest
(),
a4
)
def
test_earliest_fields_and_field_name
(
self
):
msg
=
'Cannot use both positional arguments and the field_name keyword argument.'
with
self
.
assertRaisesMessage
(
ValueError
,
msg
):
Article
.
objects
.
earliest
(
'pub_date'
,
field_name
=
'expire_date'
)
def
test_latest
(
self
):
# Because no Articles exist yet, latest() raises ArticleDoesNotExist.
with
self
.
assertRaises
(
Article
.
DoesNotExist
):
...
...
@@ -149,11 +143,6 @@ class EarliestOrLatestTests(TestCase):
Article
.
objects
.
model
.
_meta
.
get_latest_by
=
(
'pub_date'
,
'expire_date'
)
self
.
assertEqual
(
Article
.
objects
.
filter
(
pub_date
=
datetime
(
2005
,
7
,
27
))
.
latest
(),
a3
)
def
test_latest_fields_and_field_name
(
self
):
msg
=
'Cannot use both positional arguments and the field_name keyword argument.'
with
self
.
assertRaisesMessage
(
ValueError
,
msg
):
Article
.
objects
.
latest
(
'pub_date'
,
field_name
=
'expire_date'
)
def
test_latest_manual
(
self
):
# You can still use latest() with a model that doesn't have
# "get_latest_by" set -- just pass in the field name manually.
...
...
@@ -167,15 +156,6 @@ class EarliestOrLatestTests(TestCase):
Person
.
objects
.
latest
()
self
.
assertEqual
(
Person
.
objects
.
latest
(
"birthday"
),
p2
)
def
test_field_name_kwarg_deprecation
(
self
):
Person
.
objects
.
create
(
name
=
'Deprecator'
,
birthday
=
datetime
(
1950
,
1
,
1
))
msg
=
(
'The field_name keyword argument to earliest() and latest() '
'is deprecated in favor of passing positional arguments.'
)
with
self
.
assertWarnsMessage
(
RemovedInDjango30Warning
,
msg
):
Person
.
objects
.
latest
(
field_name
=
'birthday'
)
class
TestFirstLast
(
TestCase
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment