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
917fd9d0
Unverified
Kaydet (Commit)
917fd9d0
authored
Mar 19, 2019
tarafından
Hasan Ramezani
Kaydeden (comit)
Mariusz Felisiak
Nis 17, 2019
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #27755 -- Added ModelAdmin.get_inlines() hook.
üst
7d49ad76
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
45 additions
and
1 deletion
+45
-1
options.py
django/contrib/admin/options.py
+5
-1
index.txt
docs/ref/contrib/admin/index.txt
+10
-0
3.0.txt
docs/releases/3.0.txt
+4
-0
tests.py
tests/generic_inline_admin/tests.py
+26
-0
No files found.
django/contrib/admin/options.py
Dosyayı görüntüle @
917fd9d0
...
...
@@ -327,6 +327,10 @@ class BaseModelAdmin(metaclass=forms.MediaDefiningClass):
return
self
.
fieldsets
return
[(
None
,
{
'fields'
:
self
.
get_fields
(
request
,
obj
)})]
def
get_inlines
(
self
,
request
,
obj
):
"""Hook for specifying custom inlines."""
return
self
.
inlines
def
get_ordering
(
self
,
request
):
"""
Hook for specifying field ordering.
...
...
@@ -582,7 +586,7 @@ class ModelAdmin(BaseModelAdmin):
def
get_inline_instances
(
self
,
request
,
obj
=
None
):
inline_instances
=
[]
for
inline_class
in
self
.
inlines
:
for
inline_class
in
self
.
get_inlines
(
request
,
obj
)
:
inline
=
inline_class
(
self
.
model
,
self
.
admin_site
)
if
request
:
if
not
(
inline
.
has_view_or_change_permission
(
request
,
obj
)
or
...
...
docs/ref/contrib/admin/index.txt
Dosyayı görüntüle @
917fd9d0
...
...
@@ -1627,6 +1627,16 @@ templates used by the :class:`ModelAdmin` views:
instances of the classes defined in :attr:`inlines` or you might encounter
a "Bad Request" error when adding related objects.
.. method:: ModelAdmin.get_inlines(request, obj)
.. versionadded:: 3.0
The ``get_inlines`` method is given the ``HttpRequest`` and the
``obj`` being edited (or ``None`` on an add form) and is expected to return
an iterable of inlines. You can override this method to dynamically add
inlines based on the request or model instance instead of specifying them
in :attr:`ModelAdmin.inlines`.
.. method:: ModelAdmin.get_urls()
The ``get_urls`` method on a ``ModelAdmin`` returns the URLs to be used for
...
...
docs/releases/3.0.txt
Dosyayı görüntüle @
917fd9d0
...
...
@@ -47,6 +47,10 @@ Minor features
* Added support for the ``admin_order_field`` attribute on properties in
:attr:`.ModelAdmin.list_display`.
* The new :meth:`ModelAdmin.get_inlines()
<django.contrib.admin.ModelAdmin.get_inlines>` method allows specifying the
inlines based on the request or model instance.
:mod:`django.contrib.admindocs`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...
...
tests/generic_inline_admin/tests.py
Dosyayı görüntüle @
917fd9d0
...
...
@@ -429,3 +429,29 @@ class GenericInlineModelAdminTest(SimpleTestCase):
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__
)
def
test_get_inline_instances_override_get_inlines
(
self
):
class
MediaInline
(
GenericTabularInline
):
model
=
Media
class
AlternateInline
(
GenericTabularInline
):
model
=
Media
class
EpisodeAdmin
(
admin
.
ModelAdmin
):
inlines
=
(
AlternateInline
,
MediaInline
)
def
get_inlines
(
self
,
request
,
obj
):
if
hasattr
(
request
,
'name'
):
if
request
.
name
==
'alternate'
:
return
self
.
inlines
[:
1
]
elif
request
.
name
==
'media'
:
return
self
.
inlines
[
1
:
2
]
return
[]
ma
=
EpisodeAdmin
(
Episode
,
self
.
site
)
self
.
assertEqual
(
ma
.
get_inlines
(
request
,
None
),
[])
self
.
assertEqual
(
ma
.
get_inline_instances
(
request
),
[])
for
name
,
inline_class
in
((
'alternate'
,
AlternateInline
),
(
'media'
,
MediaInline
)):
request
.
name
=
name
self
.
assertEqual
(
ma
.
get_inlines
(
request
,
None
),
(
inline_class
,)),
self
.
assertEqual
(
type
(
ma
.
get_inline_instances
(
request
)[
0
]),
inline_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