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
6abd6c59
Kaydet (Commit)
6abd6c59
authored
Ara 02, 2016
tarafından
Jon Dufresne
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #27563 -- Moved "apply limit_choices_to" code from BaseModelForm to fields_for_model().
üst
6d139418
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
7 deletions
+9
-7
models.py
django/forms/models.py
+5
-7
tests.py
tests/model_forms/tests.py
+4
-0
No files found.
django/forms/models.py
Dosyayı görüntüle @
6abd6c59
...
...
@@ -170,6 +170,11 @@ def fields_for_model(model, fields=None, exclude=None, widgets=None,
formfield
=
formfield_callback
(
f
,
**
kwargs
)
if
formfield
:
# Apply ``limit_choices_to``.
if
hasattr
(
formfield
,
'queryset'
)
and
hasattr
(
formfield
,
'get_limit_choices_to'
):
limit_choices_to
=
formfield
.
get_limit_choices_to
()
if
limit_choices_to
is
not
None
:
formfield
.
queryset
=
formfield
.
queryset
.
complex_filter
(
limit_choices_to
)
field_list
.
append
((
f
.
name
,
formfield
))
else
:
ignored
.
append
(
f
.
name
)
...
...
@@ -291,13 +296,6 @@ class BaseModelForm(BaseForm):
data
,
files
,
auto_id
,
prefix
,
object_data
,
error_class
,
label_suffix
,
empty_permitted
,
use_required_attribute
=
use_required_attribute
,
)
# Apply ``limit_choices_to`` to each field.
for
field_name
in
self
.
fields
:
formfield
=
self
.
fields
[
field_name
]
if
hasattr
(
formfield
,
'queryset'
)
and
hasattr
(
formfield
,
'get_limit_choices_to'
):
limit_choices_to
=
formfield
.
get_limit_choices_to
()
if
limit_choices_to
is
not
None
:
formfield
.
queryset
=
formfield
.
queryset
.
complex_filter
(
limit_choices_to
)
def
_get_validation_exclusions
(
self
):
"""
...
...
tests/model_forms/tests.py
Dosyayı görüntüle @
6abd6c59
...
...
@@ -2854,6 +2854,10 @@ class LimitChoicesToTest(TestCase):
f
=
StumpJokeWithCustomFieldForm
()
self
.
assertEqual
(
f
.
fields
[
'custom'
]
.
queryset
,
42
)
def
test_fields_for_model_applies_limit_choices_to
(
self
):
fields
=
fields_for_model
(
StumpJoke
,
[
'has_fooled_today'
])
self
.
assertSequenceEqual
(
fields
[
'has_fooled_today'
]
.
queryset
,
[
self
.
threepwood
])
class
FormFieldCallbackTests
(
SimpleTestCase
):
...
...
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