conveniently add attributes to an action function admin action permissions publish description mark selected stories as published def makepublishedself request queryset queryset updatestatus p this is equivalent to setting some attributes with the original longer names on the function directly def makepublishedself request queryset queryset updatestatus p makepublished allowedpermissions publish makepublished shortdescription mark selected stories as published conveniently add attributes to a display function admin display booleantrue ordering publishdate description is published def ispublishedself obj return obj publishdate is not none this is equivalent to setting some attributes with the original longer names on the function directly def ispublishedself obj return obj publishdate is not none ispublished boolean true ispublished adminorderfield publishdate ispublished shortdescription is published register the given models classes and wrapped modeladmin class with admin site register class adminadmin modeladmin pass the site kwarg is an admin site to use instead of the default admin site conveniently add attributes to an action function admin action permissions publish description mark selected stories as published def make_published self request queryset queryset update status p this is equivalent to setting some attributes with the original longer names on the function directly def make_published self request queryset queryset update status p make_published allowed_permissions publish make_published short_description mark selected stories as published conveniently add attributes to a display function admin display boolean true ordering publish_date description is published def is_published self obj return obj publish_date is not none this is equivalent to setting some attributes with the original longer names on the function directly def is_published self obj return obj publish_date is not none is_published boolean true is_published admin_order_field publish_date is_published short_description is published register the given model s classes and wrapped modeladmin class with admin site register class admin admin modeladmin pass the site kwarg is an admin site to use instead of the default admin site
def action(function=None, *, permissions=None, description=None):
    

    def decorator(func):
        if permissions is not None:
            func.allowed_permissions = permissions
        if description is not None:
            func.short_description = description
        return func

    if function is None:
        return decorator
    else:
        return decorator(function)


def display(
    function=None, *, boolean=None, ordering=None, description=None, empty_value=None
):
    

    def decorator(func):
        if boolean is not None and empty_value is not None:
            raise ValueError(
                "The boolean and empty_value arguments to the @display "
                "decorator are mutually exclusive."
            )
        if boolean is not None:
            func.boolean = boolean
        if ordering is not None:
            func.admin_order_field = ordering
        if description is not None:
            func.short_description = description
        if empty_value is not None:
            func.empty_value_display = empty_value
        return func

    if function is None:
        return decorator
    else:
        return decorator(function)


def register(*models, site=None):
    
    from django.contrib.admin import ModelAdmin
    from django.contrib.admin.sites import AdminSite
    from django.contrib.admin.sites import site as default_site

    def _model_admin_wrapper(admin_class):
        if not models:
            raise ValueError("At least one model must be passed to register.")

        admin_site = site or default_site

        if not isinstance(admin_site, AdminSite):
            raise ValueError("site must subclass AdminSite")

        if not issubclass(admin_class, ModelAdmin):
            raise ValueError("Wrapped class must subclass ModelAdmin.")

        admin_site.register(models, admin_class=admin_class)

        return admin_class

    return _model_admin_wrapper