Code

Opened 2 years ago

Closed 11 months ago

#17308 closed Cleanup/optimization (fixed)

Use short description with properties in the admin

Reported by: pmartin Owned by: viciu
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

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 pmartin 2 years ago.

Download all attachments as: .zip

Change History (10)

Changed 2 years ago by pmartin

comment:1 Changed 2 years ago by anonymous

  • Needs documentation set
  • Needs tests set
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted
  • Type changed from New feature to Cleanup/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 14 months ago by viciu

  • Owner changed from nobody to viciu
  • Status changed from new to assigned

comment:3 Changed 14 months ago by viciu

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 Changed 14 months ago by viciu

  • Triage Stage changed from Accepted to Design 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 13 months ago by aaugustin

  • Triage Stage changed from Design decision needed to Accepted

comment:7 Changed 11 months ago by lpiatek

  • Needs documentation unset
  • Needs tests unset

comment:8 Changed 11 months ago by lpiatek

  • Triage Stage changed from Accepted to Ready for checkin

comment:9 Changed 11 months ago by Florian Apolloner <florian@…>

  • Resolution set to fixed
  • Status changed from assigned to closed

In cec9558fba1bc6401ea2ec6d71b816b4dfd31b28:

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

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.