2008/4/24 Raisins <[EMAIL PROTECTED]>:
>
>  I have moved along some more. Now Using this snippet (
>  http://www.djangosnippets.org/snippets/148/ )
>
>  z = FOO.objects.get(id=pram_id)
>  y = z.BAR.filter(off = False)
>  #.....
>  form_dict = {}
>  for x in y:
>         form_dict[x.id] = forms.BooleanField(required= False)
>  #....
>
>  form = DynForm()
>  form.setFields(form_dict)
>
>  That works great and creates a form with a ton of indivual checkbox
>  fields that I can refence like {{ form.## }} but it is still not what
>  I want.
>
>  I pass the form and y to the template. Now I have it set up like this.
>
>  {% for x in y_list %}
>  {{ x.other_info }}
>  {{ form.{{X.id}}  }}
>  {%endfor %}
>
>  That doesnt work, it tries to parse the {{ and fails. I tried to
>  switch it to  {{ form.x.id }} no luck on that. It seems to be looking
>  for a field named "x" not the object I am refencing.
>
>  The question now is how can you refence a variable in a template in
>  side another variable?

That is not possible using the standard template syntax which is
deliberately meant to be simple.

If you really want to do it you can either write a custom template tag
which in your case would take X.id as argument and return the correct
form field (the tmplate tag code can access the context and find the
form object). See the template_python doc for details.

However when I have needed to do this I simply add a item attribute to
each form field so in the template you can do:

{% for x in form %}
  {{x.item.some_x_attr}}
  {{x}}
{% endfor %}

To set up the item attr just do:

form = DynForm()
form.setFields(form_dict)
for x in y:
   form.fields[x.id].item = x

Obviously if you do this a lot you would modify DynForm to do all the work.

Cheers,

-- 
Phil

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

Reply via email to