Opened 13 years ago

Closed 11 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: dev
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

Description

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 13 years ago.

Download all attachments as: .zip

Change History (10)

by Pablo Martín, 13 years ago

Attachment: patch_r17159.diff added

comment:1 by anonymous, 13 years ago

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 by Wiktor, 12 years ago

Owner: changed from nobody to Wiktor
Status: newassigned

comment:3 by Wiktor, 12 years ago

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)

        self.assertEqual(
            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):
            @property
            def test_from_property(self):
                return "this if from property"
            test_from_property.short_description = 'property short description'

throwing

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

comment:4 by Wiktor, 12 years ago

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 by Aymeric Augustin, 12 years ago

Triage Stage: Design decision neededAccepted

comment:7 by lpiatek, 11 years ago

Needs documentation: unset
Needs tests: unset

comment:8 by lpiatek, 11 years ago

Triage Stage: AcceptedReady for checkin

comment:9 by Florian Apolloner <florian@…>, 11 years ago

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