Opened 12 years ago

Closed 2 years ago

Last modified 2 years ago

#16117 closed New feature (fixed)

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

Reported by: Matt Harasymczuk Owned by: Nick Pope
Component: contrib.admin Version: dev
Severity: Normal Keywords: admin, actions, list_display, readonly_fields, methods, short_description, admin_order_field, boolean, empty_value_display, allowed_permissions
Cc: kmike84@… 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

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 (14)

comment:1 Changed 12 years ago by Jannis Leidel

Component: Database layer (models, ORM)contrib.admin
Triage Stage: UnreviewedAccepted
Type: Cleanup/optimizationNew feature

comment:2 Changed 12 years ago by Jannis Leidel

Summary: Model Methods decoratorsProvide decorators to easily mark functions/methods for as list_display items or admin actions

comment:3 Changed 12 years ago by Jannis Leidel

Summary: Provide decorators to easily mark functions/methods for as list_display items or admin actionsProvide decorators to easily mark functions/methods as list_display items or admin actions

comment:4 Changed 12 years ago by Odin Hørthe Omdal

UI/UX: unset

comment:5 Changed 12 years ago by Jacob

milestone: 1.4

Milestone 1.4 deleted

comment:6 Changed 11 years ago by Mikhail Korobov

Cc: kmike84@… added

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

comment:7 Changed 8 years ago by Tim Graham

#25134 is a duplicate with some discussion.

comment:8 Changed 8 years ago by Curtis Maloney

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 years ago by Collin Anderson

Also, keep in mind allow_tags is deprecated #25135.

comment:10 Changed 3 years ago by Nick Pope

Has patch: set
Keywords: admin actions list_display readonly_fields methods short_description admin_order_field boolean empty_value_display allowed_permissions added
Owner: changed from nobody to Nick Pope
Status: newassigned
Version: master

comment:11 Changed 3 years ago by Adam Johnson

Triage Stage: AcceptedReady for checkin

comment:12 Changed 2 years ago by GitHub <noreply@…>

Resolution: fixed
Status: assignedclosed

In 9204485:

Fixed #16117 -- Added decorators for admin action and display functions.

Refs #25134, #32099.

comment:13 Changed 2 years ago by GitHub <noreply@…>

In 8f02a78:

Refs #16117 -- Made @action and @display decorators importable from django.contrib.gis.admin.

comment:14 Changed 2 years ago by Mariusz Felisiak <felisiak.mariusz@…>

In eccf40a:

[3.2.x] Refs #16117 -- Made @action and @display decorators importable from django.contrib.gis.admin.

Backport of 8f02a78695a6c07bc5b05499e6e6cf96bc25320f from master

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