I have been trying to learn Django (and Python). 

I have a form that can have up to n elements. Each of those elements has 3 
parts to it (a TextField, a TagField and a Checkbox). The form init looks 
like this

    def __init__(self, *args, **kwargs):
        
        notesAndTags = kwargs.pop('notesAndTags')        
        
        super(NotesAndTagsForm, self).__init__(*args, **kwargs)
       
        for i, tagandtext in enumerate(notesAndTags):
            self.fields['tag_%s' % i] = TagField(initial = tagandtext.tag)
            self.fields['text_%s' % i] = 
forms.CharField(widget=forms.Textarea, initial=tagandtext.text)
            self.fields['import_%s' % i] = forms.BooleanField(initial=True) 


This is based on this explanation of dynamic 
forms<http://jacobian.org/writing/dynamic-form-generation/>and the form creates 
just fine. 

I need the fields displayed together (as they were created) so I have a 
checkbox, the Tag Field and the textarea all cleanly grouped.

The question is how do you then display that form using the correct tags?   

If I do a 
 Python Syntax (Toggle Plain 
Text<http://www.daniweb.com/forums/thread340242.html#>
)
 

   1. {{ form }}
   
{{ form }}
 in the template how do I ensure that the fields are grouped together as 
they should be?  Should I override the as_table (or other method) to output 
as I see fit? 

Alternatively I can output each element (well I could) but I can't figure 
out how to access each at the same time because trying to use the formloop 
counter in an output tag produces an error.  I could zip the 3 lists into a 
single and output it using a loop BUT my concern is whether or not I could 
always guarantee that the zipped list would be present.

So what is the best practice around how to do this? 

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

Reply via email to