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
362fba87
Kaydet (Commit)
362fba87
authored
May 01, 2017
tarafından
Alexander Kavanaugh
Kaydeden (comit)
Tim Graham
May 03, 2017
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #28159 -- Fixed BaseInlineFormSet._construct_form() crash when using save_as_new.
Regression in
4a246a02
.
üst
9b2d47bc
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
3 deletions
+16
-3
models.py
django/forms/models.py
+6
-1
1.11.1.txt
docs/releases/1.11.1.txt
+3
-0
tests.py
tests/model_formsets/tests.py
+7
-2
No files found.
django/forms/models.py
Dosyayı görüntüle @
362fba87
...
...
@@ -884,12 +884,17 @@ class BaseInlineFormSet(BaseModelFormSet):
def
_construct_form
(
self
,
i
,
**
kwargs
):
form
=
super
()
.
_construct_form
(
i
,
**
kwargs
)
if
self
.
save_as_new
:
mutable
=
getattr
(
form
.
data
,
'_mutable'
,
None
)
# Allow modifying an immutable QueryDict.
if
mutable
is
not
None
:
form
.
data
.
_mutable
=
True
# Remove the primary key from the form's data, we are only
# creating new instances
form
.
data
[
form
.
add_prefix
(
self
.
_pk_field
.
name
)]
=
None
# Remove the foreign key from the form's data
form
.
data
[
form
.
add_prefix
(
self
.
fk
.
name
)]
=
None
if
mutable
is
not
None
:
form
.
data
.
_mutable
=
mutable
# Set the fk value here so that the form can do its validation.
fk_value
=
self
.
instance
.
pk
...
...
docs/releases/1.11.1.txt
Dosyayı görüntüle @
362fba87
...
...
@@ -81,3 +81,6 @@ Bugfixes
* Fixed a regression in choice ordering in form fields with grouped and
non-grouped options (:ticket:`28157`).
* Fixed crash in ``BaseInlineFormSet._construct_form()`` when using
``save_as_new`` (:ticket:`28159`).
tests/model_formsets/tests.py
Dosyayı görüntüle @
362fba87
...
...
@@ -10,6 +10,7 @@ from django.forms.models import (
BaseModelFormSet
,
_get_foreign_key
,
inlineformset_factory
,
modelformset_factory
,
)
from
django.http
import
QueryDict
from
django.test
import
TestCase
,
skipUnlessDBFeature
from
.models
import
(
...
...
@@ -699,7 +700,9 @@ class ModelFormsetTest(TestCase):
AuthorBooksFormSet
=
inlineformset_factory
(
Author
,
Book
,
can_delete
=
False
,
extra
=
2
,
fields
=
"__all__"
)
Author
.
objects
.
create
(
name
=
'Charles Baudelaire'
)
data
=
{
# An immutable QueryDict simulates request.POST.
data
=
QueryDict
(
mutable
=
True
)
data
.
update
({
'book_set-TOTAL_FORMS'
:
'3'
,
# the number of forms rendered
'book_set-INITIAL_FORMS'
:
'2'
,
# the number of forms with initial data
'book_set-MAX_NUM_FORMS'
:
''
,
# the max number of forms
...
...
@@ -708,10 +711,12 @@ class ModelFormsetTest(TestCase):
'book_set-1-id'
:
'2'
,
'book_set-1-title'
:
'Les Paradis Artificiels'
,
'book_set-2-title'
:
''
,
}
})
data
.
_mutable
=
False
formset
=
AuthorBooksFormSet
(
data
,
instance
=
Author
(),
save_as_new
=
True
)
self
.
assertTrue
(
formset
.
is_valid
())
self
.
assertIs
(
data
.
_mutable
,
False
)
new_author
=
Author
.
objects
.
create
(
name
=
'Charles Baudelaire'
)
formset
=
AuthorBooksFormSet
(
data
,
instance
=
new_author
,
save_as_new
=
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