Hello,
I want my forms to be dynamic, some parameters sucj as max_length for IntegerField varies from model to model. By using the information from here, I have written this form:
def my_form(inputname, inputlastname, inputamount):
class MyForm(forms.Form):
name = forms.CharField(max_length=50,required=True,initial=inputname)
lastname = forms.CharField(max_length=50, required=True,initial=inputlastname)
amount= forms.IntegerField(max_value=inputamount, required=True)
return MyForm
It renders well at the template when I call it like this and pass to the template:
form = my_form("David","Bowie",4)()
However I can't figure out how can I validate it, this fails:
if request.method == 'POST': form = MyForm(request.POST) if form.is_valid()