Django Model() vs Model.objects.create()

0leg picture 0leg · Oct 31, 2014 · Viewed 211.7k times · Source

What it the difference between running two commands:

foo = FooModel()

and

bar = BarModel.objects.create()

Does the second one immediately create a BarModel in the database, while for FooModel, the save() method has to be called explicitly to add it to the database?

Answer

madzohan picture madzohan · Oct 31, 2014

https://docs.djangoproject.com/en/stable/topics/db/queries/#creating-objects

To create and save an object in a single step, use the create() method.