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
10e83d48
Kaydet (Commit)
10e83d48
authored
Tem 02, 2014
tarafından
Anubhav Joshi
Kaydeden (comit)
Tim Graham
Tem 02, 2014
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #22935 -- Changed ForeignKey.default_error_messages['invalid'] to refer to correct field.
Thanks Tim Graham for suggestion and review.
üst
27ee608b
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
19 additions
and
3 deletions
+19
-3
related.py
django/db/models/fields/related.py
+5
-2
1.8.txt
docs/releases/1.8.txt
+7
-0
models.py
tests/validation/models.py
+1
-0
tests.py
tests/validation/tests.py
+6
-1
No files found.
django/db/models/fields/related.py
Dosyayı görüntüle @
10e83d48
...
@@ -1600,7 +1600,7 @@ class ForeignObject(RelatedField):
...
@@ -1600,7 +1600,7 @@ class ForeignObject(RelatedField):
class
ForeignKey
(
ForeignObject
):
class
ForeignKey
(
ForeignObject
):
empty_strings_allowed
=
False
empty_strings_allowed
=
False
default_error_messages
=
{
default_error_messages
=
{
'invalid'
:
_
(
'
%(model)
s instance with
pk
%(pk
)
r does not exist.'
)
'invalid'
:
_
(
'
%(model)
s instance with
%(field)
s
%(value
)
r does not exist.'
)
}
}
description
=
_
(
"Foreign Key (type determined by related field)"
)
description
=
_
(
"Foreign Key (type determined by related field)"
)
...
@@ -1707,7 +1707,10 @@ class ForeignKey(ForeignObject):
...
@@ -1707,7 +1707,10 @@ class ForeignKey(ForeignObject):
raise
exceptions
.
ValidationError
(
raise
exceptions
.
ValidationError
(
self
.
error_messages
[
'invalid'
],
self
.
error_messages
[
'invalid'
],
code
=
'invalid'
,
code
=
'invalid'
,
params
=
{
'model'
:
self
.
rel
.
to
.
_meta
.
verbose_name
,
'pk'
:
value
},
params
=
{
'model'
:
self
.
rel
.
to
.
_meta
.
verbose_name
,
'pk'
:
value
,
'field'
:
self
.
rel
.
field_name
,
'value'
:
value
,
},
# 'pk' is included for backwards compatibilty
)
)
def
get_attname
(
self
):
def
get_attname
(
self
):
...
...
docs/releases/1.8.txt
Dosyayı görüntüle @
10e83d48
...
@@ -391,6 +391,13 @@ Miscellaneous
...
@@ -391,6 +391,13 @@ Miscellaneous
* Support for SpatiaLite < 2.4 has been dropped.
* Support for SpatiaLite < 2.4 has been dropped.
* ``ForeignKey.default_error_message['invalid']`` has been changed from
``'%(model)s instance with pk %(pk)r does not exist.'`` to
``'%(model)s instance with %(field)s %(value)r does not exist.'`` If you are
using this message in your own code, please update the list of interpolated
parameters. Internally, Django will continue to provide the
``pk`` parameter in ``params`` for backwards compatibility.
.. _deprecated-features-1.8:
.. _deprecated-features-1.8:
Features deprecated in 1.8
Features deprecated in 1.8
...
...
tests/validation/models.py
Dosyayı görüntüle @
10e83d48
...
@@ -18,6 +18,7 @@ class ModelToValidate(models.Model):
...
@@ -18,6 +18,7 @@ class ModelToValidate(models.Model):
number
=
models
.
IntegerField
(
db_column
=
'number_val'
)
number
=
models
.
IntegerField
(
db_column
=
'number_val'
)
parent
=
models
.
ForeignKey
(
'self'
,
blank
=
True
,
null
=
True
,
limit_choices_to
=
{
'number'
:
10
})
parent
=
models
.
ForeignKey
(
'self'
,
blank
=
True
,
null
=
True
,
limit_choices_to
=
{
'number'
:
10
})
email
=
models
.
EmailField
(
blank
=
True
)
email
=
models
.
EmailField
(
blank
=
True
)
ufm
=
models
.
ForeignKey
(
'UniqueFieldsModel'
,
to_field
=
'unique_charfield'
,
blank
=
True
,
null
=
True
)
url
=
models
.
URLField
(
blank
=
True
)
url
=
models
.
URLField
(
blank
=
True
)
f_with_custom_validator
=
models
.
IntegerField
(
blank
=
True
,
null
=
True
,
validators
=
[
validate_answer_to_universe
])
f_with_custom_validator
=
models
.
IntegerField
(
blank
=
True
,
null
=
True
,
validators
=
[
validate_answer_to_universe
])
slug
=
models
.
SlugField
(
blank
=
True
)
slug
=
models
.
SlugField
(
blank
=
True
)
...
...
tests/validation/tests.py
Dosyayı görüntüle @
10e83d48
...
@@ -25,7 +25,12 @@ class BaseModelValidationTests(ValidationTestCase):
...
@@ -25,7 +25,12 @@ class BaseModelValidationTests(ValidationTestCase):
def
test_wrong_FK_value_raises_error
(
self
):
def
test_wrong_FK_value_raises_error
(
self
):
mtv
=
ModelToValidate
(
number
=
10
,
name
=
'Some Name'
,
parent_id
=
3
)
mtv
=
ModelToValidate
(
number
=
10
,
name
=
'Some Name'
,
parent_id
=
3
)
self
.
assertFailsValidation
(
mtv
.
full_clean
,
[
'parent'
])
self
.
assertFieldFailsValidationWithMessage
(
mtv
.
full_clean
,
'parent'
,
[
'model to validate instance with id
%
r does not exist.'
%
mtv
.
parent_id
])
mtv
=
ModelToValidate
(
number
=
10
,
name
=
'Some Name'
,
ufm_id
=
'Some Name'
)
self
.
assertFieldFailsValidationWithMessage
(
mtv
.
full_clean
,
'ufm'
,
[
"unique fields model instance with unique_charfield
%
r does not exist."
%
mtv
.
name
])
def
test_correct_FK_value_validates
(
self
):
def
test_correct_FK_value_validates
(
self
):
parent
=
ModelToValidate
.
objects
.
create
(
number
=
10
,
name
=
'Some Name'
)
parent
=
ModelToValidate
.
objects
.
create
(
number
=
10
,
name
=
'Some Name'
)
...
...
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