Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.

#1 Jan. 19, 2011 23:31:59

g.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Dynamic form and grouping elements


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 = TagField(initial = tagandtext.tag)
self.fields =
forms.CharField(widget=forms.Textarea, initial=tagandtext.text)
self.fields = 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 athttp://groups.google.com/group/django-users?hl=en.

Offline

Board footer

Moderator control

Enjoy the 23rd of October
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support