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
e9d1f118
Kaydet (Commit)
e9d1f118
authored
Kas 18, 2014
tarafından
MattBlack85
Kaydeden (comit)
Tim Graham
Kas 26, 2014
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #23801 -- Added warning when max_length is used with IntegerField
üst
cbb5cdd1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
0 deletions
+37
-0
__init__.py
django/db/models/fields/__init__.py
+17
-0
checks.txt
docs/ref/checks.txt
+1
-0
test_ordinary_fields.py
tests/invalid_models_tests/test_ordinary_fields.py
+19
-0
No files found.
django/db/models/fields/__init__.py
Dosyayı görüntüle @
e9d1f118
...
...
@@ -1704,6 +1704,23 @@ class IntegerField(Field):
}
description
=
_
(
"Integer"
)
def
check
(
self
,
**
kwargs
):
errors
=
super
(
IntegerField
,
self
)
.
check
(
**
kwargs
)
errors
.
extend
(
self
.
_check_max_length_warning
())
return
errors
def
_check_max_length_warning
(
self
):
if
self
.
max_length
is
not
None
:
return
[
checks
.
Warning
(
"'max_length' is ignored when used with IntegerField"
,
hint
=
"Remove 'max_length' from field"
,
obj
=
self
,
id
=
'fields.W122'
,
)
]
return
[]
@cached_property
def
validators
(
self
):
# These validators can't be added at field initialization time since
...
...
docs/ref/checks.txt
Dosyayı görüntüle @
e9d1f118
...
...
@@ -82,6 +82,7 @@ Fields
* **fields.E110**: ``BooleanField``\s do not accept null values.
* **fields.E120**: ``CharField``\s must define a ``max_length`` attribute.
* **fields.E121**: ``max_length`` must be a positive integer.
* **fields.W122**: ``max_length`` is ignored when used with ``IntegerField``.
* **fields.E130**: ``DecimalField``\s must define a ``decimal_places`` attribute.
* **fields.E131**: ``decimal_places`` must be a non-negative integer.
* **fields.E132**: ``DecimalField``\s must define a ``max_digits`` attribute.
...
...
tests/invalid_models_tests/test_ordinary_fields.py
Dosyayı görüntüle @
e9d1f118
...
...
@@ -513,6 +513,25 @@ class ImageFieldTests(IsolatedModelsTestCase):
self
.
assertEqual
(
errors
,
expected
)
class
IntegerFieldTests
(
IsolatedModelsTestCase
):
def
test_max_length_warning
(
self
):
class
Model
(
models
.
Model
):
value
=
models
.
IntegerField
(
max_length
=
2
)
value
=
Model
.
_meta
.
get_field
(
'value'
)
errors
=
Model
.
check
()
expected
=
[
DjangoWarning
(
"'max_length' is ignored when used with IntegerField"
,
hint
=
"Remove 'max_length' from field"
,
obj
=
value
,
id
=
'fields.W122'
,
)
]
self
.
assertEqual
(
errors
,
expected
)
class
TimeFieldTests
(
IsolatedModelsTestCase
):
def
test_fix_default_value
(
self
):
...
...
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