I am using James Bennetts code to create a dynamic form. I have everything working but want to save the data to a database. Has anyone got any code which does this or could show me what the best way to do this would be e.g. how the model should be set up etc?
+1
A:
Override the save()
method on your form class:
def save(self):
new_user = User.objects.create_user(username=self.cleaned_data['username'],
email=self.cleaned_data['email'],
password=self.cleaned_data['password1'])
return new_user
(taken from James Bennett's blog at Newforms, part 2)
Jeff Bradberry
2009-12-01 19:04:13
I don't have a object to override since it is different everytime and is generated on the fly
John
2009-12-02 09:24:24
I take it then that your code is based on his version of `make_contact_form` that uses `type` to generate the class?
Jeff Bradberry
2009-12-02 19:03:36
Yes thats correct. I plan to expand on his code so that instead of hard coding which form elements are required, I will pull them in from a database table which is populated by a user
John
2009-12-03 10:12:09