开发者

Django Dynamic Forms

开发者 https://www.devze.com 2022-12-13 10:19 出处:网络
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 wha开发者_开发知识库

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 wha开发者_开发知识库t the best way to do this would be e.g. how the model should be set up etc?


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)

0

精彩评论

暂无评论...
验证码 换一张
取 消