Opened 8 years ago

Closed 6 years ago

#17308 closed Cleanup/optimization (fixed)

Use short description with properties in the admin

Reported by: Pablo Martín Owned by: Wiktor
Component: contrib.admin Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


If you use a property in a list_display (e.g.) the name of the column will be a "pretty name" of the name of the property.

But this property could use "short_description" as follow (See patch)

Attachments (1)

patch_r17159.diff (616 bytes) - added by Pablo Martín 8 years ago.

Download all attachments as: .zip

Change History (10)

Changed 8 years ago by Pablo Martín

Attachment: patch_r17159.diff added

comment:1 Changed 8 years ago by anonymous

Needs documentation: set
Needs tests: set
Triage Stage: UnreviewedAccepted
Type: New featureCleanup/optimization

This needs a quick simple test, and perhaps a bullet point in the docs under the section on list_display - but otherwise looks like a good idea, as you shouldn't be penalized for making use of your methods as properties.

comment:2 Changed 7 years ago by Wiktor

Owner: changed from nobody to Wiktor
Status: newassigned

comment:3 Changed 7 years ago by Wiktor

I've reviewed a patch and it works for the use case when property is not set with @property decorator.

So this will work:

    def test_label_for_property(self):
        class MockModelAdmin(object):
            def fget(self):
                return "this if from property"
            fget.short_description = 'property short description'
            test_from_property = property(fget=fget)

            label_for_field("test_from_property", Article, model_admin=MockModelAdmin),
            'property short description'

but this will not:

    def test_label_for_property_decorator(self):
        class MockModelAdmin(object):
            def test_from_property(self):
                return "this if from property"
            test_from_property.short_description = 'property short description'


AttributeError: 'property' object has no attribute 'short_description'

comment:4 Changed 7 years ago by Wiktor

Triage Stage: AcceptedDesign decision needed

In my opinion this needs decision/discussion, because setting short_description is limited to usage of property as a function, not as a decorator.

This is better then nothing on the other hand.

I may however send a pull request (patch + tests) if this is ok.

comment:5 Changed 7 years ago by Aymeric Augustin

Triage Stage: Design decision neededAccepted

comment:7 Changed 6 years ago by lpiatek

Needs documentation: unset
Needs tests: unset

comment:8 Changed 6 years ago by lpiatek

Triage Stage: AcceptedReady for checkin

comment:9 Changed 6 years ago by Florian Apolloner <florian@…>

Resolution: fixed
Status: assignedclosed

In cec9558fba1bc6401ea2ec6d71b816b4dfd31b28:

Fixed #17308 -- Enabled the use of short_description on properties in the admin.

Note: See TracTickets for help on using tickets.
Back to Top