On 9 août, 23:37, Hayyan Rafiq <
hayya...@hotmail.com> wrote:
> Okay then which way do u recommend that i should follow in case
> i need to displays objects with different no of properties
> Example obj has propA and PropB
> {{obj.propA}}
> {{obj.propB}}
> would work but i want it to be dynamic since the no and name of properties may vary..
Then you need a custom template filter. Something like this should do
the trick:
# in your templatetags module:
@register.filter
def get_attribute(obj, name):
return getattr(obj, name, u"")
# in your template
{% load youtemplatetags %}
{% for attrname in attributes %}
{{ obj|get_attribute:attrname }}
{% endor %}