[Django] #29385: Admindocs doesn't show model properties

52 views
Skip to first unread message

Django

unread,
May 7, 2018, 6:59:58 AM5/7/18
to django-...@googlegroups.com
#29385: Admindocs doesn't show model properties
---------------------------------------------+------------------------
Reporter: bkaluza | Owner: nobody
Type: Bug | Status: new
Component: contrib.admindocs | Version: 2.0
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
---------------------------------------------+------------------------
Model properties (like one below) do not show in the admin documentation:

{{{#!python
class MyModel(models.Model):
name = models.CharField(max_length=200)
public = models.BooleanField(default=False)
date_approved = models.DateTimeField(null=True, blank=True)

@property
def status(self):
"""
returns the status of object
"""
if self.date_approved and self.public:
return "Public"
elif self.public:
return "Pending Approval"
else:
return "Private"
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/29385>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
May 7, 2018, 7:01:53 AM5/7/18
to django-...@googlegroups.com
#29385: Admindocs doesn't show model properties
-----------------------------------+--------------------------------------

Reporter: bkaluza | Owner: nobody
Type: Bug | Status: new
Component: contrib.admindocs | Version: 2.0
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------

Comment (by bkaluza):

It seem easy to fix. In file `django/contrib/admindocs/views.py` method
`ModelDetailView.get_context_data` gathers model methods, but skips the
properties as they are not methods. So we need to (1) add properties to
the condition and (2) append the property to the list of fields.

{{{#!python
# Gather model methods.
for func_name, func in model.__dict__.items():
#
# CHANGE 1: add isinstance(func, property) to the condition
#
# if inspect.isfunction(func): # old line
if inspect.isfunction(func) or isinstance(func, property):
try:
for exclude in MODEL_METHODS_EXCLUDE:
if func_name.startswith(exclude):
raise StopIteration
except StopIteration:
continue
verbose = func.__doc__
if verbose:
verbose = utils.parse_rst(utils.trim_docstring(verbose),
'model', _('model:') + opts.model_name)

#
# CHANGE 2: If this is a property, show it as a 'field'
#
if isinstance(func, property):
fields.append({
'name': func_name,
'data_type': get_return_data_type(func_name),
'verbose': verbose or '',
})
# Else if a method has no arguments, show it as a 'field',
otherwise
# as a 'method with arguments'.
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),
'verbose': verbose or '',
})
else:
arguments = get_func_full_args(func)
# Join arguments with ', ' and in case of default value,
# join it with '='. Use repr() so that strings will be
# correctly displayed.
print_arguments = ', '.join([
'='.join(list(arg_el[:1]) + [repr(el) for el in
arg_el[1:]])
for arg_el in arguments
])
methods.append({
'name': func_name,
'arguments': print_arguments,
'verbose': verbose or '',
})
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/29385#comment:1>

Django

unread,
May 7, 2018, 7:19:25 AM5/7/18
to django-...@googlegroups.com
#29385: Admindocs doesn't show model properties
-----------------------------------+--------------------------------------

Reporter: bkaluza | Owner: nobody
Type: Bug | Status: new
Component: contrib.admindocs | Version: 2.0
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------

Comment (by bkaluza):

Pull request: https://github.com/django/django/pull/9929

--
Ticket URL: <https://code.djangoproject.com/ticket/29385#comment:2>

Django

unread,
May 7, 2018, 10:26:05 AM5/7/18
to django-...@googlegroups.com
#29385: Make ModelDetailView show model properties
--------------------------------------+------------------------------------
Reporter: Bostjan Kaluza | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: contrib.admindocs | Version: 2.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Tim Graham):

* needs_better_patch: 0 => 1
* has_patch: 0 => 1
* type: Bug => Cleanup/optimization
* stage: Unreviewed => Accepted


Comment:

A test and documentation update are also required.

--
Ticket URL: <https://code.djangoproject.com/ticket/29385#comment:3>

Django

unread,
May 9, 2018, 9:06:25 AM5/9/18
to django-...@googlegroups.com
#29385: Make ModelDetailView show model properties
--------------------------------------+------------------------------------
Reporter: Bostjan Kaluza | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: contrib.admindocs | Version: 2.0

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Nat S Dunn):

* cc: Nat S Dunn (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/29385#comment:4>

Django

unread,
May 28, 2018, 4:19:20 PM5/28/18
to django-...@googlegroups.com
#29385: Make ModelDetailView show model properties
-------------------------------------+-------------------------------------
Reporter: Bostjan Kaluza | Owner:
Type: | humbertotm
Cleanup/optimization | Status: assigned
Component: contrib.admindocs | Version: 2.0

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by humbertotm):

* owner: nobody => humbertotm
* status: new => assigned


Comment:

I'd be glad to work on the required test and documentation.

--
Ticket URL: <https://code.djangoproject.com/ticket/29385#comment:5>

Django

unread,
May 29, 2018, 12:03:22 AM5/29/18
to django-...@googlegroups.com
#29385: Make ModelDetailView show model properties
-------------------------------------+-------------------------------------
Reporter: Bostjan Kaluza | Owner:
Type: | humbertotm
Cleanup/optimization | Status: assigned
Component: contrib.admindocs | Version: 2.0

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by humbertotm):

Pull request: [https://github.com/django/django/pull/10004]

Building on the fix provided by PR #9929, a unit test for the enhancement
has been added. Additional documentation has not been added as the fix
seems to fall within what is covered by
[https://docs.djangoproject.com/en/2.0/ref/contrib/admin/admindocs/ The
Django admin documentation generator]. I will be glad to continue
documenting with a bit of orientation.

Let me know if you have any comments regarding the unit test.

--
Ticket URL: <https://code.djangoproject.com/ticket/29385#comment:6>

Django

unread,
May 29, 2018, 2:50:18 AM5/29/18
to django-...@googlegroups.com
#29385: Make ModelDetailView show model properties
-------------------------------------+-------------------------------------
Reporter: Bostjan Kaluza | Owner:
Type: | humbertotm
Cleanup/optimization | Status: assigned
Component: contrib.admindocs | Version: 2.0

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Claude Paroz):

For the docs, something like `with all the fields and methods available on
it` -> `with all the fields, properties and methods available on it`, with
a `versionchanged` section stating that showing model properties has been
added.

--
Ticket URL: <https://code.djangoproject.com/ticket/29385#comment:7>

Django

unread,
May 29, 2018, 12:42:09 PM5/29/18
to django-...@googlegroups.com
#29385: Make ModelDetailView show model properties
-------------------------------------+-------------------------------------
Reporter: Bostjan Kaluza | Owner:
Type: | humbertotm
Cleanup/optimization | Status: assigned
Component: contrib.admindocs | Version: 2.0

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by humbertotm):

Replying to [comment:7 Claude Paroz]:


> For the docs, something like `with all the fields and methods available
on it` -> `with all the fields, properties and methods available on it`,
with a `versionchanged` section stating that showing model properties has
been added.

Great! I'm on it.
Thanks!

--
Ticket URL: <https://code.djangoproject.com/ticket/29385#comment:8>

Django

unread,
May 29, 2018, 2:01:50 PM5/29/18
to django-...@googlegroups.com
#29385: Make ModelDetailView show model properties
-------------------------------------+-------------------------------------
Reporter: Bostjan Kaluza | Owner:
Type: | humbertotm
Cleanup/optimization | Status: assigned
Component: contrib.admindocs | Version: 2.0

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by humbertotm):

Added documentation to PR. Let me know what you think, and how this can be
improved.
Thanks!

--
Ticket URL: <https://code.djangoproject.com/ticket/29385#comment:9>

Django

unread,
May 29, 2018, 4:22:27 PM5/29/18
to django-...@googlegroups.com
#29385: Make ModelDetailView show model properties
-------------------------------------+-------------------------------------
Reporter: Bostjan Kaluza | Owner:
Type: | humbertotm
Cleanup/optimization | Status: assigned
Component: contrib.admindocs | Version: 2.0

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Claude Paroz):

* needs_better_patch: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/29385#comment:10>

Django

unread,
May 31, 2018, 3:31:44 AM5/31/18
to django-...@googlegroups.com
#29385: Make ModelDetailView show model properties
-------------------------------------+-------------------------------------
Reporter: Bostjan Kaluza | Owner:
Type: | humbertotm
Cleanup/optimization | Status: assigned
Component: contrib.admindocs | Version: 2.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/29385#comment:11>

Django

unread,
Jun 3, 2018, 9:21:31 PM6/3/18
to django-...@googlegroups.com
#29385: Make ModelDetailView show model properties
-------------------------------------+-------------------------------------
Reporter: Bostjan Kaluza | Owner:
Type: | humbertotm
Cleanup/optimization | Status: closed
Component: contrib.admindocs | Version: 2.0
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"747ff7a30b79e12d344169200de24f88a22ddee9" 747ff7a3]:
{{{
#!CommitTicketReference repository=""
revision="747ff7a30b79e12d344169200de24f88a22ddee9"
Fixed #29385 -- Made admindocs ModelDetailView show model properties.

Original patch by bkaluza. Tests and docs by humbertotm.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/29385#comment:12>

Reply all
Reply to author
Forward
0 new messages