h3d0 h3d0 - 5 months ago 48
Python Question

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

What it the difference between running two commands:

foo = FooModel()


and

bar = BarModel.objects.create()


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

Answer

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

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

Comments