Re: bound field object - dynamic forms

2012-09-06 Thread Tom Evans
On Wed, Sep 5, 2012 at 9:18 PM, mjh  wrote:
> yes it is being passed to the template as I can access the label, choices,
> help_text, required items of the boundfield object...
>
> i.e., {{ issue.label }} {{ issue.choices }} {{ issue.help_text }}
>
> I can get everything it seems apart from the form object !!!
>
> {{ issue }} writes to the template:  at 0x40d03d0>
>
>

You want that fields forms.BoundField, not the forms.Field object you
currently have. A BoundField is bound with the specific data in the
form, especially if the form was submitted, and has things like error
messages and a proper label field associated with them (you are
outputting the raw label text currently).

Change form.issues to be a list of the ids of the fields you require,
rather than the forms.Field object and then use an attribute fetcher
template tag in the template to retrieve the bound field from the
form.

Eg using this dict_get template tag:

http://permalink.gmane.org/gmane.comp.python.django.user/106119

and storing the ids of the issues in form.issue_list

{% for issue_id in form.issue_list %}
 {% with form|dict_get:issue_id as issue %}

{{ issue.errors }}
{{ issue.label_tag }}: {{ issue }}

{% endwith %}
{% endfor %}

Hope that helps

Tom

-- 
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.



Re: bound field object - dynamic forms

2012-09-05 Thread mjh
yes it is being passed to the template as I can access the label, choices, 
help_text, required items of the boundfield object...

i.e., {{ issue.label }} {{ issue.choices }} {{ issue.help_text }}

I can get everything it seems apart from the form object !!!

{{ issue }} writes to the template: 


???



On Wednesday, 5 September 2012 18:56:17 UTC+1, Amyth wrote:
>
> check if it is being passed to template.
>
> {% if issue %}
>   {{ issue }}
> {% else %}
>   Issue was not passed #Debug
> {% endif %}
>
> On Wed, Sep 5, 2012 at 8:45 PM, Mando >wrote:
>
>> are you passing it to the template?
>>
>>
>> On Wednesday, September 5, 2012 7:09:57 AM UTC-5, mjh wrote:
>>>
>>> tried {{ issue.x }} x = 0,1,2,3 but nothing is displayed in the template
>>>
>>> any other thoughts?
>>>
>>> On Monday, 3 September 2012 22:53:03 UTC+1, somecallitblues wrote:

 Try {{ issue.0}} and {{ issue.1}}
 On Sep 4, 2012 5:55 AM, "mjh"  wrote:

> Hi all - not sure how to show the choicefield dropdown in my template?
>
> Am generating a dynamic form (note: for issue in issues in forms.py) and 
> appending the fields to self.issue_list
>
> in the template I am looping over these fields ({% for issue in 
> form.issue_list %}) and can write out the label {{ issue.label }} but if 
> write out {{ issue }} I simply get the bound field object written to 
> template ().
>
> Question is how do I get the html dropdown to display in the template??
>
>
>
> >>> forms.py
> def __init__(self, item, *args, **kwargs):
> super(ItemAnalysisForm, self).__init__(*args, **kwargs)
> issue_choice = (('1', 'Reduced'),
> ('2', 'Maintained'),
> ('3', 'Increased')
> )
> issues = item.issue.all()
>
> self.issue_list = []
> self.a_list = []
> # generate dynamic issue dropdowns...
> for issue in issues:
> self.fields['issue-' + str(issue.pk)] = 
> forms.ChoiceField(label=issue.**name , 
> choices=issue_choice, required=False)
> self.a_list.append(self.**fields['issue-' + str(issue.pk)])
> self.issue_list.append(self.**fields['issue-' + 
> str(issue.pk)])
> self.fields['text'] = forms.CharField(label='text', 
> required=True, widget=forms.Textarea(attrs={'**rows':25,'cols':'100'}))
> self.a_list.append(self.**fields['text'])
>
>
> >>> template
> {% 
> csrf_token %}
> 
> Individual Issue Outcome:
> 
> {% for issue in form.issue_list %}
> 
> {{ issue.label }}: {{ issue }}
> 
> {% endfor %}
> 
> 
> 
> Comment:
> 
> {{ form.text }}
> 
>
> 
>
>  -- 
> 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/-/**XSMbUGOJyvMJ
> .
> To post to this group, send email to django...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users...@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 view this discussion on the web visit 
>> https://groups.google.com/d/msg/django-users/-/up3KXt_tm2YJ.
>>
>> To post to this group, send email to django...@googlegroups.com
>> .
>> To unsubscribe from this group, send email to 
>> django-users...@googlegroups.com .
>> For more options, visit this group at 
>> http://groups.google.com/group/django-users?hl=en.
>>
>
>
>
> -- 
> Thanks & Regards
> 
>
> Amyth [Admin - Techstricks]
> Email - aroras@gmail.com , ad...@techstricks.com
> Twitter - @a_myth_
> http://techstricks.com/
>  

-- 
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/-/H8fJ3O-vDwQJ.
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.



Re: bound field object - dynamic forms

2012-09-05 Thread Amyth Arora
check if it is being passed to template.

{% if issue %}
  {{ issue }}
{% else %}
  Issue was not passed #Debug
{% endif %}

On Wed, Sep 5, 2012 at 8:45 PM, Mando  wrote:

> are you passing it to the template?
>
>
> On Wednesday, September 5, 2012 7:09:57 AM UTC-5, mjh wrote:
>>
>> tried {{ issue.x }} x = 0,1,2,3 but nothing is displayed in the template
>>
>> any other thoughts?
>>
>> On Monday, 3 September 2012 22:53:03 UTC+1, somecallitblues wrote:
>>>
>>> Try {{ issue.0}} and {{ issue.1}}
>>> On Sep 4, 2012 5:55 AM, "mjh"  wrote:
>>>
 Hi all - not sure how to show the choicefield dropdown in my template?

 Am generating a dynamic form (note: for issue in issues in forms.py) and 
 appending the fields to self.issue_list

 in the template I am looping over these fields ({% for issue in 
 form.issue_list %}) and can write out the label {{ issue.label }} but if 
 write out {{ issue }} I simply get the bound field object written to 
 template ().

 Question is how do I get the html dropdown to display in the template??



 >>> forms.py
 def __init__(self, item, *args, **kwargs):
 super(ItemAnalysisForm, self).__init__(*args, **kwargs)
 issue_choice = (('1', 'Reduced'),
 ('2', 'Maintained'),
 ('3', 'Increased')
 )
 issues = item.issue.all()

 self.issue_list = []
 self.a_list = []
 # generate dynamic issue dropdowns...
 for issue in issues:
 self.fields['issue-' + str(issue.pk)] = 
 forms.ChoiceField(label=issue.**name , 
 choices=issue_choice, required=False)
 self.a_list.append(self.**fields['issue-' + str(issue.pk)])
 self.issue_list.append(self.**fields['issue-' + str(issue.pk)])
 self.fields['text'] = forms.CharField(label='text', required=True, 
 widget=forms.Textarea(attrs={'**rows':25,'cols':'100'}))
 self.a_list.append(self.**fields['text'])


 >>> template
 {% 
 csrf_token %}
 
 Individual Issue Outcome:
 
 {% for issue in form.issue_list %}
 
 {{ issue.label }}: {{ issue }}
 
 {% endfor %}
 
 
 
 Comment:
 
 {{ form.text }}
 

 

  --
 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/-/**XSMbUGOJyvMJ
 .
 To post to this group, send email to django...@googlegroups.com.
 To unsubscribe from this group, send email to
 django-users...@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 view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/up3KXt_tm2YJ.
>
> 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.
>



-- 
Thanks & Regards


Amyth [Admin - Techstricks]
Email - aroras.offic...@gmail.com, ad...@techstricks.com
Twitter - @a_myth_
http://techstricks.com/

-- 
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.



Re: bound field object - dynamic forms

2012-09-05 Thread Mando
are you passing it to the template?

On Wednesday, September 5, 2012 7:09:57 AM UTC-5, mjh wrote:
>
> tried {{ issue.x }} x = 0,1,2,3 but nothing is displayed in the template
>
> any other thoughts?
>
> On Monday, 3 September 2012 22:53:03 UTC+1, somecallitblues wrote:
>>
>> Try {{ issue.0}} and {{ issue.1}}
>> On Sep 4, 2012 5:55 AM, "mjh"  wrote:
>>
>>> Hi all - not sure how to show the choicefield dropdown in my template?
>>>
>>> Am generating a dynamic form (note: for issue in issues in forms.py) and 
>>> appending the fields to self.issue_list
>>>
>>> in the template I am looping over these fields ({% for issue in 
>>> form.issue_list %}) and can write out the label {{ issue.label }} but if 
>>> write out {{ issue }} I simply get the bound field object written to 
>>> template ().
>>>
>>> Question is how do I get the html dropdown to display in the template??
>>>
>>>
>>>
>>> >>> forms.py
>>> def __init__(self, item, *args, **kwargs):
>>> super(ItemAnalysisForm, self).__init__(*args, **kwargs)
>>> issue_choice = (('1', 'Reduced'),
>>> ('2', 'Maintained'),
>>> ('3', 'Increased')
>>> )
>>> issues = item.issue.all()
>>>
>>> self.issue_list = []
>>> self.a_list = []
>>> # generate dynamic issue dropdowns...
>>> for issue in issues:
>>> self.fields['issue-' + str(issue.pk)] = 
>>> forms.ChoiceField(label=issue.name, choices=issue_choice, required=False)
>>> self.a_list.append(self.fields['issue-' + str(issue.pk)])
>>> self.issue_list.append(self.fields['issue-' + str(issue.pk)])
>>> self.fields['text'] = forms.CharField(label='text', required=True, 
>>> widget=forms.Textarea(attrs={'rows':25,'cols':'100'}))
>>> self.a_list.append(self.fields['text'])
>>>
>>>
>>> >>> template
>>> {% 
>>> csrf_token %}
>>> 
>>> Individual Issue Outcome:
>>> 
>>> {% for issue in form.issue_list %}
>>> 
>>> {{ issue.label }}: {{ issue }}
>>> 
>>> {% endfor %}
>>> 
>>> 
>>> 
>>> Comment:
>>> 
>>> {{ form.text }}
>>> 
>>>
>>> 
>>>
>>>  -- 
>>> 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/-/XSMbUGOJyvMJ.
>>> To post to this group, send email to django...@googlegroups.com.
>>> To unsubscribe from this group, send email to 
>>> django-users...@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 view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/up3KXt_tm2YJ.
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.



Re: bound field object - dynamic forms

2012-09-05 Thread mjh
tried {{ issue.x }} x = 0,1,2,3 but nothing is displayed in the template

any other thoughts?

On Monday, 3 September 2012 22:53:03 UTC+1, somecallitblues wrote:
>
> Try {{ issue.0}} and {{ issue.1}}
> On Sep 4, 2012 5:55 AM, "mjh" > 
> wrote:
>
>> Hi all - not sure how to show the choicefield dropdown in my template?
>>
>> Am generating a dynamic form (note: for issue in issues in forms.py) and 
>> appending the fields to self.issue_list
>>
>> in the template I am looping over these fields ({% for issue in 
>> form.issue_list %}) and can write out the label {{ issue.label }} but if 
>> write out {{ issue }} I simply get the bound field object written to 
>> template ().
>>
>> Question is how do I get the html dropdown to display in the template??
>>
>>
>>
>> >>> forms.py
>> def __init__(self, item, *args, **kwargs):
>> super(ItemAnalysisForm, self).__init__(*args, **kwargs)
>> issue_choice = (('1', 'Reduced'),
>> ('2', 'Maintained'),
>> ('3', 'Increased')
>> )
>> issues = item.issue.all()
>>
>> self.issue_list = []
>> self.a_list = []
>> # generate dynamic issue dropdowns...
>> for issue in issues:
>> self.fields['issue-' + str(issue.pk)] = 
>> forms.ChoiceField(label=issue.name, choices=issue_choice, required=False)
>> self.a_list.append(self.fields['issue-' + str(issue.pk)])
>> self.issue_list.append(self.fields['issue-' + str(issue.pk)])
>> self.fields['text'] = forms.CharField(label='text', required=True, 
>> widget=forms.Textarea(attrs={'rows':25,'cols':'100'}))
>> self.a_list.append(self.fields['text'])
>>
>>
>> >>> template
>> {% 
>> csrf_token %}
>> 
>> Individual Issue Outcome:
>> 
>> {% for issue in form.issue_list %}
>> 
>> {{ issue.label }}: {{ issue }}
>> 
>> {% endfor %}
>> 
>> 
>> 
>> Comment:
>> 
>> {{ form.text }}
>> 
>>
>> 
>>
>>  -- 
>> 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/-/XSMbUGOJyvMJ.
>> To post to this group, send email to django...@googlegroups.com
>> .
>> To unsubscribe from this group, send email to 
>> django-users...@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 view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/T4kUV4SutHkJ.
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.



Re: bound field object - dynamic forms

2012-09-03 Thread Mario Gudelj
Try {{ issue.0}} and {{ issue.1}}
On Sep 4, 2012 5:55 AM, "mjh"  wrote:

> Hi all - not sure how to show the choicefield dropdown in my template?
>
> Am generating a dynamic form (note: for issue in issues in forms.py) and 
> appending the fields to self.issue_list
>
> in the template I am looping over these fields ({% for issue in 
> form.issue_list %}) and can write out the label {{ issue.label }} but if 
> write out {{ issue }} I simply get the bound field object written to template 
> ().
>
> Question is how do I get the html dropdown to display in the template??
>
>
>
> >>> forms.py
> def __init__(self, item, *args, **kwargs):
> super(ItemAnalysisForm, self).__init__(*args, **kwargs)
> issue_choice = (('1', 'Reduced'),
> ('2', 'Maintained'),
> ('3', 'Increased')
> )
> issues = item.issue.all()
>
> self.issue_list = []
> self.a_list = []
> # generate dynamic issue dropdowns...
> for issue in issues:
> self.fields['issue-' + str(issue.pk)] = 
> forms.ChoiceField(label=issue.name, choices=issue_choice, required=False)
> self.a_list.append(self.fields['issue-' + str(issue.pk)])
> self.issue_list.append(self.fields['issue-' + str(issue.pk)])
> self.fields['text'] = forms.CharField(label='text', required=True, 
> widget=forms.Textarea(attrs={'rows':25,'cols':'100'}))
> self.a_list.append(self.fields['text'])
>
>
> >>> template
> {% 
> csrf_token %}
> 
> Individual Issue Outcome:
> 
> {% for issue in form.issue_list %}
> 
> {{ issue.label }}: {{ issue }}
> 
> {% endfor %}
> 
> 
> 
> Comment:
> 
> {{ form.text }}
> 
>
> 
>
>  --
> 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/-/XSMbUGOJyvMJ.
> 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.



bound field object - dynamic forms

2012-09-03 Thread mjh


Hi all - not sure how to show the choicefield dropdown in my template?

Am generating a dynamic form (note: for issue in issues in forms.py) and 
appending the fields to self.issue_list

in the template I am looping over these fields ({% for issue in form.issue_list 
%}) and can write out the label {{ issue.label }} but if write out {{ issue }} 
I simply get the bound field object written to template 
().

Question is how do I get the html dropdown to display in the template??



>>> forms.py
def __init__(self, item, *args, **kwargs):
super(ItemAnalysisForm, self).__init__(*args, **kwargs)
issue_choice = (('1', 'Reduced'),
('2', 'Maintained'),
('3', 'Increased')
)
issues = item.issue.all()

self.issue_list = []
self.a_list = []
# generate dynamic issue dropdowns...
for issue in issues:
self.fields['issue-' + str(issue.pk)] = 
forms.ChoiceField(label=issue.name, choices=issue_choice, required=False)
self.a_list.append(self.fields['issue-' + str(issue.pk)])
self.issue_list.append(self.fields['issue-' + str(issue.pk)])
self.fields['text'] = forms.CharField(label='text', required=True, 
widget=forms.Textarea(attrs={'rows':25,'cols':'100'}))
self.a_list.append(self.fields['text'])


>>> template
{% 
csrf_token %}

Individual Issue Outcome:

{% for issue in form.issue_list %}

{{ issue.label }}: {{ issue }}

{% endfor %}



Comment:

{{ form.text }}




-- 
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/-/XSMbUGOJyvMJ.
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.