[BangPypers] Heterogeneous forms in django formset
Amit Sethi
amit.pureenergy at gmail.com
Tue Mar 13 07:06:08 CET 2012
Hi all , I have a certain problem with django forms that seems to me
should definitely have a solution already written.
I have a couple of different forms that are submitted in the same view
something like ...( Sorry just using pseudo code for now )..
class Form1():
#different attributes
Class Form2()
#different attributes
`<html>`
<form >
{{ 1-instance-Form1 }}
{{ 2-instance-Form1 }}
{{ 1-instance-Form2 }}
{{ 2-instance-Form2 }}
</form>
`</html>`
Apart from that I want to give the user the ability to add a form
instance of one of the form classes available through jquery so the
form might become
`<html>`
<form >
{{ 1-instance-Form1 }}
{{ 2-instance-Form1 }}
{{ 1-instance-Form2 }}
{{ 2-instance-Form2 }}
{{ 3-instance-Form2 }}
</form>
`</html>`
Now while looking for a solution to handle such a problem I came
accross the concept of django formset which as the documentation
describes is a collection of instances of the same Form class. However
as I can see formsets can have the ability to handle heterogenous
forms as well:
With some definitions changed
class BaseHeterogenousFormSet(StrAndUnicode):
def append(form):
#add one more form to the formset
def is_valid():
#run is_valid for each of the forms in the formset
def clean():
#run the clean for each of the forms ...
Is there something wrong with the way i am thinking about this problem
?? Is this a proper way a handle the problem that I am describing
--
A-M-I-T S|S
More information about the BangPypers
mailing list