The obvious ways are:

1. Provide a model method that returns a string representing the type
of the instance, compare against that
2. Decorate the instance with an attribute giving the name of the type
as a string...

Can't change the instance (I really think you can still decorate it in
the view, python is flexible that way, but), instead of rows of
instances, return rows of wrapper objects that have the type name as
above, and the original instance as another attribute.

On Tue, Jul 3, 2012 at 3:50 PM, Russ Abbott <russ.abb...@gmail.com> wrote:
> I'm generating a table. I want the cells to be different depending on the
> type of the content. How do I test for the type of the content? I'd like to
> do something like this.
>
>             <tbody>
>             {% for row in rows %}
>                 <tr>
>                     {% for cell in row %}
>                         <td>
>                                 {% if isinstance( {{ cell }}, list) %}
>                                     <ul>
>                                     {% for element in cell %}
>                                         <li>{{  element  }}</li>
>                                     {% endfor %}
>                                     <ul>
>                                 {% else %}
>                                     {{ cell }}
>                                 {% endif %}
>                         </td>
>                     {% endfor %}
>                 </tr>
>             {% endfor %}
>             </tbody>
>
> But "{% if isinstance( {{ cell }}, list) %}" is not allowed. Apparently I
> can't call a function in an {% if ...  %} tag.  Is there another way to do
> this?
>
> Thanks.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/jRlkDDGDgk0J.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to