Thanks, Roseman. I was hoping I wouldn't have to resort to custom
filters or tags, because it obfuscates template code that should be
really simple. Also, I don't think filters can be applied to this
slightly modified example:

{% for person in people %}
  <tr>
  {% for col in columns %}
    <td{% if person.get(col) > too_large %} class="too-large"{% endif
%}>
      {{ person.get(col) }}
    </td>
  {% endfor %}
{% endfor %}

I know Django templates were intentionally designed to disallow
passing arguments to methods; therefore, I'm assuming there must be a
clean way of implementing this example that I'm just not aware of.

On Feb 19, 12:27 am, Daniel Roseman <dan...@roseman.org.uk> wrote:
> On Feb 19, 8:04 am, Daniel Wong <allyourc...@gmail.com> wrote:
>
>
>
> > Seems like there's no good way to do this, because you can't call
> > methods that take > 0 arguments.
>
> > Here's an example of the sort of thing I'm trying to do. Imagine
> > you're trying to create a spreadsheet like view:
>
> > {% for person in people %}
> >   <tr>
> >   {% for col in columns %}
> >     <td>{{ person.get(col) }}</td>
> >   {% endfor %}
> > {% endfor %}
>
> > Seems like you'd have to use custom tags to achieve this, but that
> > seems way too complicated for something so simple. Is there a better
> > way?
>
> Writing a custom filter for this is the correct way - and it's a three-
> line job:
>
> @register.filter
> def get_obj(obj, value):
>     return obj.get(value)
>
> --
> DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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