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
1c05fe65
Kaydet (Commit)
1c05fe65
authored
Tem 25, 2018
tarafından
Carlton Gibson
Kaydeden (comit)
Tim Graham
Tem 25, 2018
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Refs #13091 -- Added test for commit=False idiom with partial unique_together validation.
üst
c0e3c65b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
0 deletions
+28
-0
tests.py
tests/model_forms/tests.py
+28
-0
No files found.
tests/model_forms/tests.py
Dosyayı görüntüle @
1c05fe65
...
...
@@ -855,6 +855,34 @@ class UniqueTest(TestCase):
self
.
assertEqual
(
len
(
form
.
errors
),
1
)
self
.
assertEqual
(
form
.
errors
[
'__all__'
],
[
'Price with this Price and Quantity already exists.'
])
def
test_unique_together_exclusion
(
self
):
"""
Forms don't validate unique_together constraints when only part of the
constraint is included in the form's fields. This allows using
form.save(commit=False) and then assigning the missing field(s) to the
model instance.
"""
class
BookForm
(
forms
.
ModelForm
):
class
Meta
:
model
=
DerivedBook
fields
=
(
'isbn'
,
'suffix1'
)
# The unique_together is on suffix1/suffix2 but only suffix1 is part
# of the form. The fields must have defaults, otherwise they'll be
# skipped by other logic.
self
.
assertEqual
(
DerivedBook
.
_meta
.
unique_together
,
((
'suffix1'
,
'suffix2'
),))
for
name
in
(
'suffix1'
,
'suffix2'
):
with
self
.
subTest
(
name
=
name
):
field
=
DerivedBook
.
_meta
.
get_field
(
name
)
self
.
assertEqual
(
field
.
default
,
0
)
# The form fails validation with "Derived book with this Suffix1 and
# Suffix2 already exists." if the unique_together validation isn't
# skipped.
DerivedBook
.
objects
.
create
(
isbn
=
'12345'
)
form
=
BookForm
({
'isbn'
:
'56789'
,
'suffix1'
:
'0'
})
self
.
assertTrue
(
form
.
is_valid
(),
form
.
errors
)
def
test_multiple_field_unique_together
(
self
):
"""
When the same field is involved in multiple unique_together
...
...
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