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
747ff7a3
Kaydet (Commit)
747ff7a3
authored
May 29, 2018
tarafından
humbertotm
Kaydeden (comit)
Tim Graham
Haz 04, 2018
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #29385 -- Made admindocs ModelDetailView show model properties.
Original patch by bkaluza. Tests and docs by humbertotm.
üst
085ebc5f
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
25 additions
and
7 deletions
+25
-7
views.py
django/contrib/admindocs/views.py
+10
-4
admindocs.txt
docs/ref/contrib/admin/admindocs.txt
+7
-3
models.py
tests/admin_docs/models.py
+4
-0
test_views.py
tests/admin_docs/test_views.py
+4
-0
No files found.
django/contrib/admindocs/views.py
Dosyayı görüntüle @
747ff7a3
...
...
@@ -256,7 +256,7 @@ class ModelDetailView(BaseAdminDocsView):
methods
=
[]
# Gather model methods.
for
func_name
,
func
in
model
.
__dict__
.
items
():
if
inspect
.
isfunction
(
func
):
if
inspect
.
isfunction
(
func
)
or
isinstance
(
func
,
property
)
:
try
:
for
exclude
in
MODEL_METHODS_EXCLUDE
:
if
func_name
.
startswith
(
exclude
):
...
...
@@ -267,9 +267,15 @@ class ModelDetailView(BaseAdminDocsView):
verbose
=
verbose
and
(
utils
.
parse_rst
(
utils
.
trim_docstring
(
verbose
),
'model'
,
_
(
'model:'
)
+
opts
.
model_name
)
)
# If a method has no arguments, show it as a 'field', otherwise
# as a 'method with arguments'.
if
func_has_no_args
(
func
)
and
not
func_accepts_kwargs
(
func
)
and
not
func_accepts_var_args
(
func
):
# Show properties and methods without arguments as fields.
# Otherwise, show as a 'method with arguments'.
if
isinstance
(
func
,
property
):
fields
.
append
({
'name'
:
func_name
,
'data_type'
:
get_return_data_type
(
func_name
),
'verbose'
:
verbose
or
''
})
elif
func_has_no_args
(
func
)
and
not
func_accepts_kwargs
(
func
)
and
not
func_accepts_var_args
(
func
):
fields
.
append
({
'name'
:
func_name
,
'data_type'
:
get_return_data_type
(
func_name
),
...
...
docs/ref/contrib/admin/admindocs.txt
Dosyayı görüntüle @
747ff7a3
...
...
@@ -51,9 +51,13 @@ Model reference
===============
The **models** section of the ``admindocs`` page describes each model in the
system along with all the fields and methods available on it. Relationships
to other models appear as hyperlinks. Descriptions are pulled from ``help_text``
attributes on fields or from docstrings on model methods.
system along with all the fields, properties, and methods available on it.
Relationships to other models appear as hyperlinks. Descriptions are pulled
from ``help_text`` attributes on fields or from docstrings on model methods.
.. versionchanged:: 2.2
Older versions don't display model properties.
A model with useful documentation might look like this::
...
...
tests/admin_docs/models.py
Dosyayı görüntüle @
747ff7a3
...
...
@@ -52,6 +52,10 @@ class Person(models.Model):
def
dummy_function
(
self
,
baz
,
rox
,
*
some_args
,
**
some_kwargs
):
return
some_kwargs
@property
def
a_property
(
self
):
return
'a_property'
def
suffix_company_name
(
self
,
suffix
=
'ltd'
):
return
self
.
company
.
name
+
suffix
...
...
tests/admin_docs/test_views.py
Dosyayı görüntüle @
747ff7a3
...
...
@@ -208,6 +208,10 @@ class TestModelDetailView(TestDataMixin, AdminDocsTestCase):
"""
self
.
assertContains
(
self
.
response
,
"<td>baz, rox, *some_args, **some_kwargs</td>"
)
def
test_instance_of_property_methods_are_displayed
(
self
):
"""Model properties are displayed as fields."""
self
.
assertContains
(
self
.
response
,
'<td>a_property</td>'
)
def
test_method_data_types
(
self
):
company
=
Company
.
objects
.
create
(
name
=
"Django"
)
person
=
Person
.
objects
.
create
(
first_name
=
"Human"
,
last_name
=
"User"
,
company
=
company
)
...
...
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