Can a dictionary be passed to django models on create?

If title and body are fields in your model, then you can deliver the keyword arguments in your dictionary using the ** operator Assuming your model is called MyModel : create instance of model m = MyModel(**data_dict) # don't forget to save to database! M.save() As for your second question, the dictionary has to be the final argument. Again extra and extra2 should be fields in the model m2 =MyModel(extra='hello', extra2='world', **data_dict) m2.save().

If title and body are fields in your model, then you can deliver the keyword arguments in your dictionary using the ** operator. Assuming your model is called MyModel: # create instance of model m = MyModel(**data_dict) # don't forget to save to database! M.save() As for your second question, the dictionary has to be the final argument.

Again, extra and extra2 should be fields in the model. M2 =MyModel(extra='hello', extra2='world', **data_dict) m2.save().

3 Thanks, that is exactly what I was looking to do. Also, as a side note just based off your post. You don't have to call the save method when using Model.objects.

Create(**data_dict). You probably already know this but just a heads up. – clarence Oct 15 '09 at 14:00 I've not used the objects.

Create method before, so you've taught me something new. – Alasdair Oct 15 '09 at 14:13 2 also objects. Create returns a pointer to the new model, with a valid pk filled in.

This means you can immediately use it to build related models. – Tom Leys Oct 16 '09 at 6:21.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions


Thank You!
send