#31558: Support the use of boolean attribute on properties in the admin.
-------------------------------------+-------------------------------------
Reporter: Alexandre Poitevin | Owner: Hasan
| Ramezani
Type: New feature | Status: assigned
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Alexandre Poitevin):
Thanks for accept my ticket.
I was hoping to contribute and make the pull request myself, but I’m a new
to Django, so…
Anyway I would like to say just 2 things:
1. I don’t understand what is the difference between the decorator and
calling explicitly `property`.
I saw a similar statement in the documentation. But in fact, the effect is
the same:
{{{
>>> class C:
... def m(self): ...
... m.attr = 42
... m = property(m)
...
>>> C.m.attr
Traceback (most recent call last):
...
AttributeError: 'property' object has no attribute 'attr'
>>> C.m.fget.attr
42
>>> class C:
... @property
... def m(self): ...
... m.fget.attr = 42
...
>>> C.m.attr
Traceback (most recent call last):
...
AttributeError: 'property' object has no attribute 'attr'
>>> C.m.fget.attr
42
}}}
So the original method is stored as a `fget` attribute of the property,
with or without the decorator, so I don’t see why this feature couldn’t be
achieve with the decorator.
2. After navigating in the source code and made a little work of
debugging, I found two functions that may the ones requiring modification
to enable this feature:
`contrib.admin.templatetags.items_for_result`
`contrib.admin.utils.lookup_fields`
In the second:
{{{
# For non-field values, the value is either a method, property or
# returned via a callable.
if callable(name):
attr = name
value = attr(obj)
}}}
And in the first :
{{{
try:
f, attr, value = lookup_field(field_name, result,
cl.model_admin)
except ObjectDoesNotExist:
result_repr = empty_value_display
else:
empty_value_display = getattr(attr, 'empty_value_display',
empty_value_display)
if f is None or f.auto_created:
if field_name == 'action_checkbox':
row_classes = ['action-checkbox']
boolean = getattr(attr, 'boolean', False) # <= HERE !
result_repr = display_for_value(value,
empty_value_display, boolean)
}}}
By the way, this one (`items_for_result`) has no unit tests, or at least I
didn’t see anyone (`grep -nr "items_for_result" tests/`).
--
Ticket URL: <https://code.djangoproject.com/ticket/31558#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/074.115aee04d51dda563537f2f571be8fcf%40djangoproject.com.