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?

@lukasvinclav
Copy link
Contributor

Hey, first of all thanks for the idea. On one side, I understand why you need that but from my perspective I don't want push more logic into actions at the moment. Your implementation is fine but it still requires docs, tests and some examples in the demo project.

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.

2 participants