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
2c9e9563
Kaydet (Commit)
2c9e9563
authored
Ock 17, 2015
tarafından
Tim Graham
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Removed ModelAdmin.get_formsets() per deprecation timeline; refs #20702.
üst
3b570dbc
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
3 additions
and
119 deletions
+3
-119
options.py
django/contrib/admin/options.py
+2
-37
index.txt
docs/ref/contrib/admin/index.txt
+0
-20
tests.py
tests/generic_inline_admin/tests.py
+1
-62
No files found.
django/contrib/admin/options.py
Dosyayı görüntüle @
2c9e9563
...
...
@@ -721,47 +721,12 @@ class ModelAdmin(BaseModelAdmin):
self
.
get_changelist_form
(
request
),
extra
=
0
,
fields
=
self
.
list_editable
,
**
defaults
)
def
_get_formsets
(
self
,
request
,
obj
):
"""
Helper function that exists to allow the deprecation warning to be
executed while this function continues to return a generator.
"""
for
inline
in
self
.
get_inline_instances
(
request
,
obj
):
yield
inline
.
get_formset
(
request
,
obj
)
def
get_formsets
(
self
,
request
,
obj
=
None
):
warnings
.
warn
(
"ModelAdmin.get_formsets() is deprecated and will be removed in "
"Django 1.9. Use ModelAdmin.get_formsets_with_inlines() instead."
,
RemovedInDjango19Warning
,
stacklevel
=
2
)
return
self
.
_get_formsets
(
request
,
obj
)
def
get_formsets_with_inlines
(
self
,
request
,
obj
=
None
):
"""
Yields formsets and the corresponding inlines.
"""
# We call get_formsets() [deprecated] and check if it triggers a
# warning. If it does, then it's ours and we can safely ignore it, but
# if it doesn't then it has been overridden so we must warn about the
# deprecation.
with
warnings
.
catch_warnings
(
record
=
True
)
as
w
:
warnings
.
simplefilter
(
"always"
)
formsets
=
self
.
get_formsets
(
request
,
obj
)
if
len
(
w
)
!=
1
or
not
issubclass
(
w
[
0
]
.
category
,
RemovedInDjango19Warning
):
warnings
.
warn
(
"ModelAdmin.get_formsets() is deprecated and will be removed in "
"Django 1.9. Use ModelAdmin.get_formsets_with_inlines() instead."
,
RemovedInDjango19Warning
,
stacklevel
=
2
)
if
formsets
:
zipped
=
zip
(
formsets
,
self
.
get_inline_instances
(
request
,
None
))
for
formset
,
inline
in
zipped
:
yield
formset
,
inline
else
:
for
inline
in
self
.
get_inline_instances
(
request
,
obj
):
yield
inline
.
get_formset
(
request
,
obj
),
inline
for
inline
in
self
.
get_inline_instances
(
request
,
obj
):
yield
inline
.
get_formset
(
request
,
obj
),
inline
def
get_paginator
(
self
,
request
,
queryset
,
per_page
,
orphans
=
0
,
allow_empty_first_page
=
True
):
return
self
.
paginator
(
queryset
,
per_page
,
orphans
,
allow_empty_first_page
)
...
...
docs/ref/contrib/admin/index.txt
Dosyayı görüntüle @
2c9e9563
...
...
@@ -1514,26 +1514,6 @@ templates used by the :class:`ModelAdmin` views:
You may also simply return a custom :class:`~django.forms.ModelForm` class
directly.
.. method:: ModelAdmin.get_formsets(request, obj=None)
.. deprecated:: 1.7
Use :meth:`get_formsets_with_inlines()` instead.
Yields :class:`InlineModelAdmin`\s for use in admin add and change views.
For example if you wanted to display a particular inline only in the change
view, you could override ``get_formsets`` as follows::
class MyModelAdmin(admin.ModelAdmin):
inlines = [MyInline, SomeOtherInline]
def get_formsets(self, request, obj=None):
for inline in self.get_inline_instances(request, obj):
# hide MyInline in the add view
if isinstance(inline, MyInline) and obj is None:
continue
yield inline.get_formset(request, obj)
.. method:: ModelAdmin.get_formsets_with_inlines(request, obj=None)
Yields (``FormSet``, :class:`InlineModelAdmin`) pairs for use in admin add
...
...
tests/generic_inline_admin/tests.py
Dosyayı görüntüle @
2c9e9563
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
import
warnings
from
django.contrib
import
admin
from
django.contrib.admin.sites
import
AdminSite
...
...
@@ -9,8 +8,7 @@ from django.contrib.contenttypes.admin import GenericTabularInline
from
django.contrib.contenttypes.forms
import
generic_inlineformset_factory
from
django.forms.formsets
import
DEFAULT_MAX_NUM
from
django.forms.models
import
ModelForm
from
django.test
import
RequestFactory
,
TestCase
,
ignore_warnings
,
override_settings
from
django.utils.deprecation
import
RemovedInDjango19Warning
from
django.test
import
RequestFactory
,
TestCase
,
override_settings
# local test models
from
.admin
import
MediaInline
,
MediaPermanentInline
,
site
as
admin_site
...
...
@@ -432,49 +430,6 @@ class GenericInlineModelAdminTest(TestCase):
form
=
ma
.
get_formset
(
None
)
.
form
self
.
assertEqual
(
form
.
_meta
.
fields
,
[
'url'
,
'description'
])
def
test_get_formsets_with_inlines
(
self
):
"""
get_formsets() triggers a deprecation warning when get_formsets is
overridden.
"""
class
MediaForm
(
ModelForm
):
class
Meta
:
model
=
Media
exclude
=
[
'url'
]
class
MediaInline
(
GenericTabularInline
):
exclude
=
[
'description'
]
form
=
MediaForm
model
=
Media
class
EpisodeAdmin
(
admin
.
ModelAdmin
):
inlines
=
[
MediaInline
]
def
get_formsets
(
self
,
request
,
obj
=
None
):
return
[]
with
warnings
.
catch_warnings
(
record
=
True
)
as
w
:
warnings
.
simplefilter
(
"always"
)
ma
=
EpisodeAdmin
(
Episode
,
self
.
site
)
list
(
ma
.
get_formsets_with_inlines
(
request
))
# Verify that the deprecation warning was triggered when get_formsets was called
# This verifies that we called that method.
self
.
assertEqual
(
len
(
w
),
1
)
self
.
assertTrue
(
issubclass
(
w
[
0
]
.
category
,
RemovedInDjango19Warning
))
class
EpisodeAdmin
(
admin
.
ModelAdmin
):
inlines
=
[
MediaInline
]
with
warnings
.
catch_warnings
(
record
=
True
)
as
w
:
warnings
.
simplefilter
(
"always"
)
ma
=
EpisodeAdmin
(
Episode
,
self
.
site
)
list
(
ma
.
get_formsets_with_inlines
(
request
))
self
.
assertEqual
(
len
(
w
),
0
)
@ignore_warnings
(
category
=
RemovedInDjango19Warning
)
def
test_get_formsets_with_inlines_returns_tuples
(
self
):
"""
Ensure that get_formsets_with_inlines() returns the correct tuples.
...
...
@@ -500,19 +455,3 @@ class GenericInlineModelAdminTest(TestCase):
inlines
=
ma
.
get_inline_instances
(
request
)
for
(
formset
,
inline
),
other_inline
in
zip
(
ma
.
get_formsets_with_inlines
(
request
),
inlines
):
self
.
assertIsInstance
(
formset
,
other_inline
.
get_formset
(
request
)
.
__class__
)
class
EpisodeAdmin
(
admin
.
ModelAdmin
):
inlines
=
[
AlternateInline
,
MediaInline
]
def
get_formsets
(
self
,
request
,
obj
=
None
):
# Override get_formsets to force the usage of get_formsets in
# ModelAdmin.get_formsets_with_inlines() then ignore the
# warning raised by ModelAdmin.get_formsets_with_inlines()
return
self
.
_get_formsets
(
request
,
obj
)
ma
=
EpisodeAdmin
(
Episode
,
self
.
site
)
inlines
=
ma
.
get_inline_instances
(
request
)
for
(
formset
,
inline
),
other_inline
in
zip
(
ma
.
get_formsets_with_inlines
(
request
),
inlines
):
self
.
assertIsInstance
(
formset
,
other_inline
.
get_formset
(
request
)
.
__class__
)
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