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
06a11ef6
Kaydet (Commit)
06a11ef6
authored
May 27, 2018
tarafından
Demur Nodia
Kaydeden (comit)
Tim Graham
Tem 30, 2018
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #26819 -- Fixed BaseModelFormSet.validate_unique() "unhashable type: list" crash.
üst
c090ea97
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
2 deletions
+33
-2
models.py
django/forms/models.py
+6
-2
tests.py
tests/model_formsets/tests.py
+27
-0
No files found.
django/forms/models.py
Dosyayı görüntüle @
06a11ef6
...
...
@@ -696,8 +696,12 @@ class BaseModelFormSet(BaseFormSet):
for
field
in
unique_check
if
field
in
form
.
cleaned_data
)
# Reduce Model instances to their primary key values
row_data
=
tuple
(
d
.
_get_pk_val
()
if
hasattr
(
d
,
'_get_pk_val'
)
else
d
for
d
in
row_data
)
row_data
=
tuple
(
d
.
_get_pk_val
()
if
hasattr
(
d
,
'_get_pk_val'
)
# Prevent "unhashable type: list" errors later on.
else
tuple
(
d
)
if
isinstance
(
d
,
list
)
else
d
for
d
in
row_data
)
if
row_data
and
None
not
in
row_data
:
# if we've already seen it then we have a uniqueness failure
if
row_data
in
seen_data
:
...
...
tests/model_formsets/tests.py
Dosyayı görüntüle @
06a11ef6
...
...
@@ -1459,6 +1459,33 @@ class ModelFormsetTest(TestCase):
self
.
assertEqual
(
player1
.
team
,
team
)
self
.
assertEqual
(
player1
.
name
,
'Bobby'
)
def
test_inlineformset_with_arrayfield
(
self
):
class
SimpleArrayField
(
forms
.
CharField
):
"""A proxy for django.contrib.postgres.forms.SimpleArrayField."""
def
to_python
(
self
,
value
):
value
=
super
()
.
to_python
(
value
)
return
value
.
split
(
','
)
if
value
else
[]
class
BookForm
(
forms
.
ModelForm
):
title
=
SimpleArrayField
()
class
Meta
:
model
=
Book
fields
=
(
'title'
,)
BookFormSet
=
inlineformset_factory
(
Author
,
Book
,
form
=
BookForm
)
data
=
{
'book_set-TOTAL_FORMS'
:
'3'
,
'book_set-INITIAL_FORMS'
:
'0'
,
'book_set-MAX_NUM_FORMS'
:
''
,
'book_set-0-title'
:
'test1,test2'
,
'book_set-1-title'
:
'test1,test2'
,
'book_set-2-title'
:
'test3,test4'
,
}
author
=
Author
.
objects
.
create
(
name
=
'test'
)
formset
=
BookFormSet
(
data
,
instance
=
author
)
self
.
assertEqual
(
formset
.
errors
,
[{},
{
'__all__'
:
[
'Please correct the duplicate values below.'
]},
{}])
def
test_model_formset_with_custom_pk
(
self
):
# a formset for a Model that has a custom primary key that still needs to be
# added to the formset automatically
...
...
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