Insert params into database as full object?
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)
精彩评论