[Fixed]-Generate HTML using Django-Polymorphic models

1👍

I’d be reluctant to code it like that.

First, you’ll need to pass Text and Image in your context, and regardless you can’t call a function in a template with parameters.

I’d be inclined to either write a template tag or filter, or better, just add a property to the class that returns the type of “thing” it is, which you could put directly into the <li></li>

class Foo(PolymorphicModel):
    def description(self):
        return self.__class__.__name__

And…

<ul>
{% for c in content %}
        <li>c.description</li>
{% endfor %}
</ul>

Leave a comment