Thursday, June 26, 2014

Re: Handling checkbox inputs



On Thursday, June 26, 2014 1:03:47 PM UTC+5:30, roman wrote:
Hello,

the {{j.i}} can not work as you expect. If i understand you correctly
you would like to do something like getattr(list, i) in the template.

In order to do this you have 2 possibilities:

1) Write a custom template tag like this
http://stackoverflow.com/questions/844746/performing-a-getattr-style-lookup-in-a-django-template

2) Prepare the data in the view so that you can iterate over it more easily:

result  = []
for i in info:
  for j in list:
    result.append(getattr(j, i))
return render(request, 'display.html', {'result': result})

{% for r in result %}
 <p>{{r}}</p>
{% endfor %}



While waiting for the reply, I worked out another method to do this. If interested you may have a look at https://github.com/saloni10/Django_SchoolApp/tree/master/info/template and https://github.com/saloni10/Django_SchoolApp/blob/master/info/views.py
I tried this too and it worked. Thanks ! 

--
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+unsubscribe@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.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/187ac577-cc9d-41d7-806d-60213f66c8a8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment