Re: Need Help Iterating Through a Form With HTML Interspersed

2007-12-01 Thread machineghost

> (You did remember to pass in 'firstSetOfFields' as a variable in your 
> template context, right?).
*sigh* Sadly, I didn't; as soon as I did everything worked fine;
thanks.

Jeremy

On Dec 1, 4:26 pm, "Karen Tracey" <[EMAIL PROTECTED]> wrote:
> On 12/1/07, machineghost <[EMAIL PROTECTED]> wrote:
>
>
>
>
>
> > First off thanks in advance for any help you can provide.  My problem
> > is that I have a very long form with a very repetitive layout:
> > 
> >   {{ field.label }}
> >   {{ field }}
> > 
> > which should in theory be perfect for wrapping inside a {% for field
> > in form %} {% endfor %} loop; right?  Except there's one problem:
> > every so often in this form there are divider rows that need to go in
> > between the field rows.
>
> > At first I thought I could just break the form fields in to lists, and
> > then iterate through those lists separately, ie:
> > (in view)
> > firstSetOfFields = [form["field1"], form["field2"], ...]
> > (in template)
> > {% foreach field in firstSetOfFields %}
> > but that didn't work at all, because firstSetOfFields was empty on the
> > template (I guess it has something to do with the result of
> > aForm["blah"] in a view not returning the same thing as aForm.blah on
> > the template?).
>
> I don't understand why this approach didn't work.  I do essentially this in
> a form I have.  I'd try a little harder to understand what went wrong here
> before moving onto your other approaches.  (You did remember to pass in
> 'firstSetOfFields' as a variable in your template context, right?).
>
> Karen
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Need Help Iterating Through a Form With HTML Interspersed

2007-12-01 Thread Karen Tracey
On 12/1/07, machineghost <[EMAIL PROTECTED]> wrote:
>
>
> First off thanks in advance for any help you can provide.  My problem
> is that I have a very long form with a very repetitive layout:
> 
>   {{ field.label }}
>   {{ field }}
> 
> which should in theory be perfect for wrapping inside a {% for field
> in form %} {% endfor %} loop; right?  Except there's one problem:
> every so often in this form there are divider rows that need to go in
> between the field rows.
>
> At first I thought I could just break the form fields in to lists, and
> then iterate through those lists separately, ie:
> (in view)
> firstSetOfFields = [form["field1"], form["field2"], ...]
> (in template)
> {% foreach field in firstSetOfFields %}
> but that didn't work at all, because firstSetOfFields was empty on the
> template (I guess it has something to do with the result of
> aForm["blah"] in a view not returning the same thing as aForm.blah on
> the template?).


I don't understand why this approach didn't work.  I do essentially this in
a form I have.  I'd try a little harder to understand what went wrong here
before moving onto your other approaches.  (You did remember to pass in
'firstSetOfFields' as a variable in your template context, right?).

Karen

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Need Help Iterating Through a Form With HTML Interspersed

2007-12-01 Thread machineghost

P.S.  I also tried using {% ifequals field.__repr__
form.field1.__repr__ %} to compare the objects, but Django
(intelligently) prevents you from accessing __ methods in templates.

On Dec 1, 3:17 pm, machineghost <[EMAIL PROTECTED]> wrote:
> First off thanks in advance for any help you can provide.  My problem
> is that I have a very long form with a very repetitive layout:
> 
>   {{ field.label }}
>   {{ field }}
> 
> which should in theory be perfect for wrapping inside a {% for field
> in form %} {% endfor %} loop; right?  Except there's one problem:
> every so often in this form there are divider rows that need to go in
> between the field rows.
>
> At first I thought I could just break the form fields in to lists, and
> then iterate through those lists separately, ie:
> (in view)
> firstSetOfFields = [form["field1"], form["field2"], ...]
> (in template)
> {% foreach field in firstSetOfFields %}
> but that didn't work at all, because firstSetOfFields was empty on the
> template (I guess it has something to do with the result of
> aForm["blah"] in a view not returning the same thing as aForm.blah on
> the template?).
>
> Next I thought I could use an {%ifequal field form.field1 %} to
> identify when I was on a field which had a divider row before it.
> However, since those two aren't technically equal, they never matched,
> and my divider rows never got displayed.
>
> I then tried the same thing using the "field.label" and
> "form.field1.label" ... and that actually worked.  Unfortunately
> however, two of the fields in my form have the same label, and both of
> them are supposed to have (different) divider rows before their row,
> so that method ultimately failed also.
>
> I know I could just manually lay out every field on my template, but
> this is a really long form and it kills me to have lots of hard-coded
> repetitive HTML when I know there's got to be some way to follow the
> DRY principle and reduce it all to a for loop.  Can anyone help me
> figure out how to do so?
>
> Jeremy
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---