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
14e2b1b0
Kaydet (Commit)
14e2b1b0
authored
Ara 11, 2018
tarafından
Patrik Sletmo
Kaydeden (comit)
Tim Graham
Ock 01, 2019
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #29981 -- Fixed inline formsets with a OnetoOneField primary key that uses to_field.
üst
02c07be9
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
4 deletions
+25
-4
models.py
django/forms/models.py
+6
-2
models.py
tests/model_formsets_regress/models.py
+9
-0
tests.py
tests/model_formsets_regress/tests.py
+10
-2
No files found.
django/forms/models.py
Dosyayı görüntüle @
14e2b1b0
...
...
@@ -958,8 +958,12 @@ class BaseInlineFormSet(BaseModelFormSet):
kwargs
=
{
'label'
:
getattr
(
form
.
fields
.
get
(
name
),
'label'
,
capfirst
(
self
.
fk
.
verbose_name
))
}
if
self
.
fk
.
remote_field
.
field_name
!=
self
.
fk
.
remote_field
.
model
.
_meta
.
pk
.
name
:
kwargs
[
'to_field'
]
=
self
.
fk
.
remote_field
.
field_name
# The InlineForeignKeyField assumes that the foreign key relation is
# based on the parent model's pk. If this isn't the case, set to_field
# to correctly resolve the initial form value.
if
self
.
fk
.
remote_field
.
field_name
!=
self
.
fk
.
remote_field
.
model
.
_meta
.
pk
.
name
:
kwargs
[
'to_field'
]
=
self
.
fk
.
remote_field
.
field_name
# If we're adding a new object, ignore a parent's auto-generated key
# as it will be regenerated on the save request.
...
...
tests/model_formsets_regress/models.py
Dosyayı görüntüle @
14e2b1b0
...
...
@@ -16,6 +16,15 @@ class UserProfile(models.Model):
about
=
models
.
TextField
()
class
UserPreferences
(
models
.
Model
):
user
=
models
.
OneToOneField
(
User
,
models
.
CASCADE
,
to_field
=
'username'
,
primary_key
=
True
,
)
favorite_number
=
models
.
IntegerField
()
class
ProfileNetwork
(
models
.
Model
):
profile
=
models
.
ForeignKey
(
UserProfile
,
models
.
CASCADE
,
to_field
=
"user"
)
network
=
models
.
IntegerField
()
...
...
tests/model_formsets_regress/tests.py
Dosyayı görüntüle @
14e2b1b0
...
...
@@ -8,8 +8,8 @@ from django.forms.utils import ErrorDict, ErrorList
from
django.test
import
TestCase
from
.models
import
(
Host
,
Manager
,
Network
,
ProfileNetwork
,
Restaurant
,
User
,
UserPr
ofile
,
UserSite
,
Host
,
Manager
,
Network
,
ProfileNetwork
,
Restaurant
,
User
,
UserPr
eferences
,
User
Profile
,
User
Site
,
)
...
...
@@ -171,6 +171,14 @@ class InlineFormsetTests(TestCase):
# Testing the inline model's relation
self
.
assertEqual
(
formset
[
0
]
.
instance
.
user_id
,
"guido"
)
def
test_inline_model_with_primary_to_field
(
self
):
"""An inline model with a OneToOneField with to_field & primary key."""
FormSet
=
inlineformset_factory
(
User
,
UserPreferences
,
exclude
=
(
'is_superuser'
,))
user
=
User
.
objects
.
create
(
username
=
'guido'
,
serial
=
1337
)
UserPreferences
.
objects
.
create
(
user
=
user
,
favorite_number
=
10
)
formset
=
FormSet
(
instance
=
user
)
self
.
assertEqual
(
formset
[
0
]
.
fields
[
'user'
]
.
initial
,
'guido'
)
def
test_inline_model_with_to_field_to_rel
(
self
):
"""
#13794 --- An inline model with a to_field to a related field of a
...
...
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