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
6252fd63
Kaydet (Commit)
6252fd63
authored
Kas 23, 2016
tarafından
Adam Chainz
Kaydeden (comit)
Tim Graham
Kas 25, 2016
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #27532 -- Deprecated Model._meta.has_auto_field
üst
cb7bbf97
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
46 additions
and
8 deletions
+46
-8
helpers.py
django/contrib/admin/helpers.py
+2
-2
base.py
django/db/models/base.py
+1
-1
__init__.py
django/db/models/fields/__init__.py
+1
-3
options.py
django/db/models/options.py
+15
-2
deprecation.txt
docs/internals/deprecation.txt
+2
-0
1.11.txt
docs/releases/1.11.txt
+3
-0
test_removedindjango21.py
tests/model_meta/test_removedindjango21.py
+22
-0
No files found.
django/contrib/admin/helpers.py
Dosyayı görüntüle @
6252fd63
...
...
@@ -350,12 +350,12 @@ class InlineAdminForm(AdminForm):
def
needs_explicit_pk_field
(
self
):
# Auto fields are editable (oddly), so need to check for auto or non-editable pk
if
self
.
form
.
_meta
.
model
.
_meta
.
has_
auto_field
or
not
self
.
form
.
_meta
.
model
.
_meta
.
pk
.
editable
:
if
self
.
form
.
_meta
.
model
.
_meta
.
auto_field
or
not
self
.
form
.
_meta
.
model
.
_meta
.
pk
.
editable
:
return
True
# Also search any parents for an auto field. (The pk info is propagated to child
# models so that does not need to be checked in parents.)
for
parent
in
self
.
form
.
_meta
.
model
.
_meta
.
get_parent_list
():
if
parent
.
_meta
.
has_
auto_field
:
if
parent
.
_meta
.
auto_field
:
return
True
return
False
...
...
django/db/models/base.py
Dosyayı görüntüle @
6252fd63
...
...
@@ -900,7 +900,7 @@ class Model(six.with_metaclass(ModelBase)):
if
not
pk_set
:
fields
=
[
f
for
f
in
fields
if
f
is
not
meta
.
auto_field
]
update_pk
=
bool
(
meta
.
has_auto_field
and
not
pk_set
)
update_pk
=
meta
.
auto_field
and
not
pk_set
result
=
self
.
_do_insert
(
cls
.
_base_manager
,
using
,
fields
,
update_pk
,
raw
)
if
update_pk
:
setattr
(
self
,
meta
.
pk
.
attname
,
result
)
...
...
django/db/models/fields/__init__.py
Dosyayı görüntüle @
6252fd63
...
...
@@ -948,10 +948,8 @@ class AutoField(Field):
return
int
(
value
)
def
contribute_to_class
(
self
,
cls
,
name
,
**
kwargs
):
assert
not
cls
.
_meta
.
has_auto_field
,
\
"A model can't have more than one AutoField."
assert
not
cls
.
_meta
.
auto_field
,
"A model can't have more than one AutoField."
super
(
AutoField
,
self
)
.
contribute_to_class
(
cls
,
name
,
**
kwargs
)
cls
.
_meta
.
has_auto_field
=
True
cls
.
_meta
.
auto_field
=
self
def
formfield
(
self
,
**
kwargs
):
...
...
django/db/models/options.py
Dosyayı görüntüle @
6252fd63
...
...
@@ -17,7 +17,8 @@ from django.db.models.fields.related import OneToOneField
from
django.utils
import
six
from
django.utils.datastructures
import
ImmutableList
,
OrderedSet
from
django.utils.deprecation
import
(
RemovedInDjango20Warning
,
warn_about_renamed_method
,
RemovedInDjango20Warning
,
RemovedInDjango21Warning
,
warn_about_renamed_method
,
)
from
django.utils.encoding
import
force_text
,
python_2_unicode_compatible
from
django.utils.functional
import
cached_property
...
...
@@ -113,7 +114,6 @@ class Options(object):
self
.
required_db_vendor
=
None
self
.
meta
=
meta
self
.
pk
=
None
self
.
has_auto_field
=
False
self
.
auto_field
=
None
self
.
abstract
=
False
self
.
managed
=
True
...
...
@@ -825,3 +825,16 @@ class Options(object):
# Store result into cache for later access
self
.
_get_fields_cache
[
cache_key
]
=
fields
return
fields
@property
def
has_auto_field
(
self
):
warnings
.
warn
(
'Model._meta.has_auto_field is deprecated in favor of checking if '
'Model._meta.auto_field is not None.'
,
RemovedInDjango21Warning
,
stacklevel
=
2
)
return
self
.
auto_field
is
not
None
@has_auto_field.setter
def
has_auto_field
(
self
,
value
):
pass
docs/internals/deprecation.txt
Dosyayı görüntüle @
6252fd63
...
...
@@ -46,6 +46,8 @@ details on these changes.
* The ``USE_ETAGS`` setting will be removed. ``CommonMiddleware`` and
``django.utils.cache.patch_response_headers()`` will no longer set ETags.
* The ``Model._meta.has_auto_field`` attribute will be removed.
.. _deprecation-removed-in-2.0:
2.0
...
...
docs/releases/1.11.txt
Dosyayı görüntüle @
6252fd63
...
...
@@ -707,3 +707,6 @@ Miscellaneous
``ETag`` header to responses regardless of the setting. ``CommonMiddleware``
and ``django.utils.cache.patch_response_headers()`` will no longer set ETags
when the deprecation ends.
* ``Model._meta.has_auto_field`` is deprecated in favor of checking if
``Model._meta.auto_field is not None``.
tests/model_meta/test_removedindjango21.py
0 → 100644
Dosyayı görüntüle @
6252fd63
import
warnings
from
django.test
import
SimpleTestCase
from
.models
import
Person
class
HasAutoFieldTests
(
SimpleTestCase
):
def
test_get_warns
(
self
):
with
warnings
.
catch_warnings
(
record
=
True
)
as
warns
:
warnings
.
simplefilter
(
'always'
)
Person
.
_meta
.
has_auto_field
self
.
assertEqual
(
len
(
warns
),
1
)
self
.
assertEqual
(
str
(
warns
[
0
]
.
message
),
'Model._meta.has_auto_field is deprecated in favor of checking if '
'Model._meta.auto_field is not None.'
,
)
def
test_set_does_nothing
(
self
):
Person
.
_meta
.
has_auto_field
=
True
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