开发者

Insert params into database as full object?

开发者 https://www.devze.com 2023-01-16 06:36 出处:网络
un rails i can simply insert the params into the database with one command, when all form-field name开发者_如何学运维s are the same like the model-field names. is this possible in django as well, or d

un rails i can simply insert the params into the database with one command, when all form-field name开发者_如何学运维s are the same like the model-field names. is this possible in django as well, or do i have to set each param individually. i have like 20 fields, so it's a bit of a mess.. :)

something like:

blah = Contact()
blah.content = params[]
blah.save()

thanks!


Well, if you're using a form, you should use a ModelForm, so you can do form.save().

But generally, you can instantiate an object from a dictionary of parameters using the **kwargs format:

blah = Contact(**params)
0

精彩评论

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