Hello, I transferred the logic to the view instead of trying to handle it in the template. So i pass to the template a list of tuples containing the html string generated by newforms. This way i handle dynamic created fields and easily lay down the elements the way i want. Note that i put a field between the label of another field. in the view :
filter_fields.append((filter_form["field_%s"%counter], filter_form["value_ %s"%counter].label_tag(), filter_form["comparison_ %s"%counter], filter_form["value_ %s"%counter])) than in the template it is easy to get to handle it since it is only a list of strings. You could easily add any html tag on it. {% for ff in filter_fields %} <div id="filter_{{forloop.counter0}}"> {{ff.0}} {{ff.1}} {{ff.2}} {{ff.3}} ..... cheers, Eduardo On May 6, 11:13 am, "Joseph Heck" <[EMAIL PROTECTED]> wrote: > A site I frequently work with has the forms mostly laid out using <dl> > and CSS to style it up all nicely. The newforms doesn't have a as_dl > method, and my designer is pitching a bit of fit that we can't give > him the pieces/parts of the form to lay out with a more complex setup. > > When I looked into it, I saw that some patches to generate "as_dl" > methods on newforms had been turned down. (Fine, we can add that too a > subclass and work around it). I think I'm missing something about how > I can hand the layout control to the designer though - telling them to > just deal with what {{ form.as_ul }} about got my teeth kicked in. > > Is it expected that with any newforms form object you'll be able to > reference it in the template with something like: > > {% for field in form %} > <p>{{ field.label }} {{ field }}</p> > {% endfor %} > > And does anyone have some examples where the newforms are worked up to > any extent in templates? I need to learn what we can do, and I'm > having a hard time finding many references to using newforms from > inside of templates. > > -joe > > On 4/30/07, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: > > > > > On Tue, 2007-05-01 at 10:49 +1000, Malcolm Tredinnick wrote: > > > On Mon, 2007-04-30 at 08:47 +0200, Mario Graziosi wrote: > > > > I have a form with several checkboxes created dynamically, where each > > > > field has a name similar to "mycheck_xxx". From within the template I > > > > don't know how many checks the form holds, since these are built > > > > dynamically. How can I render them using the Django template system? > > > > > For example, this is my Form (using newforms): > > > > > class FormList(forms.Form): > > > > def __init__(self, queues, *args, **kwargs): > > > > super(FormList, self).__init__(*args, **kwargs) > > > > # Create several check boxes > > > > for n in range(5): > > > > fieldname = 'mycheck_%d' % n > > > > self.fields[fieldname] = forms.BooleanField(required=False) > > > > > This is the template (one of several tries). Obviously, it doesn't work, > > > > but it reflects what I'd like to get on my form: > > > > > {% for fieldname in form.fields.keys %} > > > > <p>{{ form.fieldname }}</p> > > > > {% endfor %} > > > > Normally, once you've constructed a form class, you render it into your > > > template using {{ form.as_p }} or a related method. Since you've put > > > your extra fields into the normal self.fields attribute, the rendering > > > method will render those fields automatically. > > > > If you want the presentation to change somehow, you write your own > > > presentation method that you call. > > > > Alternatively, if you knew the name of the widgets, you could use > > > {{ form.mycheck_1 }} to do really fine-grained rendering and placement, > > > but if you want to loop through the list of these widgets, you will need > > > to have a method on your FormList class that takes a parameter and > > > returns the equivalent of my_form["mycheck_1"] (changing the string > > > based on the parameter). > > > Sorry, this is all a complete repeat of what JeffH wrote elsewhere in > > the thread. Somehow I didn't realise I wasn't at the end of the thread > > yet. :-( > > > My apologies for the duplicate information. Read what JeffH wrote. He's > > wise and all-knowing. > > > Malcolm --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---