Are you saying that you need control over which of an item's attributes are
shown and which are not and/or the order in which attributes are shown, or
are you saying that the way python/django converts the attributes to
strings does not meet your requirements, or both?

Your approach can certainly handle both, provided those who will be
maintaining it will have no trouble understanding it.

Rather than  a template filter, I would probably opt for a model method,
producing a list of strings over which the inner "for" could iterate.  Such
a method has access to all aspects of, so it could behave differently
depending on class, allowing for mixed lists, if you prefer.

Bill

On Sun, Mar 3, 2013 at 9:03 AM, Serge G. Spaolonzi <se...@cobalys.com>wrote:

> I am looking for best way to access object attributes described in a
> external list.
> The user case is to display a list of objects for different classes
> showing only some attributes, every list will contain only objects of the
> same kind, all the functionality repeats except the attributes to be
> displayed that vary according to the list.
> In the view I have a factory that retrieves the different
> objects transparently.
>
> The two solutions I have now are:
>
> 1) Iterate through attributes:
>
> items: is a list of items of the same kind
> item_display_field: is a list of field to be displayed
> getattribute: is a custom filter
>
> {% for item in items %}
>>     {% for field in item_display_field %}
>>         {{ item | getattribute:field }}
>>     {% endfor  %}
>> </br>
>> {% endfor  %}
>
>
> 2) Faster but less DRY is to keep the view factory but specify different
> templates according the class, I will have to repeat the code but win
> the processor time used to iterate through attributes.
>
> Is there a better way to do it in Django templates?
>
> Thanks
>
> --
> Serge G. Spaolonzi
> Cobalys Systems
> http://www.cobalys.com
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

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


Reply via email to