Opened 5 years ago

Last modified 8 months ago

#16117 new New feature

Provide decorators to easily mark functions/methods as list_display items or admin actions

Reported by: haras Owned by: nobody
Component: contrib.admin Version:
Severity: Normal Keywords:
Cc: kmike84@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

How about changing:

model_method.allow_tags = True
model_method.short_description = _('Model Method')

into:

@options(allow_tags=True, short_description=_('Model Method'))

or:

@allow_tags
@short_desctiption(_('Model Method'))

?

discussion at Django Developers Group

Change History (9)

comment:1 Changed 5 years ago by jezdez

  • Component changed from Database layer (models, ORM) to contrib.admin
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted
  • Type changed from Cleanup/optimization to New feature

comment:2 Changed 5 years ago by jezdez

  • Summary changed from Model Methods decorators to Provide decorators to easily mark functions/methods for as list_display items or admin actions

comment:3 Changed 5 years ago by jezdez

  • Summary changed from Provide decorators to easily mark functions/methods for as list_display items or admin actions to Provide decorators to easily mark functions/methods as list_display items or admin actions

comment:4 Changed 5 years ago by velmont

  • UI/UX unset

comment:5 Changed 5 years ago by jacob

  • milestone 1.4 deleted

Milestone 1.4 deleted

comment:6 Changed 4 years ago by kmike

  • Cc kmike84@… added

I've released a simple app for this some time ago: https://github.com/kmike/django-admin-decorators

comment:7 Changed 9 months ago by timgraham

#25134 is a duplicate with some discussion.

comment:8 Changed 8 months ago by funkybob

In discussion with someone this morning, I whipped up this

class admin_list(object):
    def __init__(self, boolean=None, order_field=None, allow_tags=None, short_description=None):
        self.boolean = boolean
        self.order_field = order_field
        self.allow_tags = allow_tags
        self.short_description=short_description

    def __call__(self, attr):
        if self.boolean is not None:
            attr.boolean = self.boolean
        if self.order_field is not None:
            attr.admin_order_field = self.order_field
        if self.allow_tags is not None:
            attr.allow_tags = self.allow_tags
        if self.short_description is not None:
            attr.short_description = short_description
        return attr

Then asked if anyone thought it'd be useful, and @timgraham pointed me to this ticket. I'll dump this here for now... feel free to bike shed the names, or I'll make a PR if you like.

comment:9 Changed 8 months ago by collinanderson

Also, keep in mind allow_tags is deprecated #25135.

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