Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

ohrstrom
Copy link

Adds a template option to @display decorator.

The template option expects a Django template, which is rendered with the provided context.

class DemoAdmin(ModelAdmin):
    list_display = [
        "display_template",
    ]

    @display(
        description="Template",
        template="demo/admin/demo_template.html",
    )
    def display_template(self, obj):
        return {
            "name": obj.name,
            "count": obj.related.count(),
        }
<!-- demo/admin/demo_template.html -->
{{ name }} <sup>{{ count }}</sup>

This makes it easier to render arbitrary templates directly through the decorator, without needing to call render_to_string in the admin classes.

Would this be helpful?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant