Should the save method be called after every create
method or does calling the create
method automatically call the save
method?
If the save
method is called automatically after creating an object then what would be a good use-case for the save
method?
Thanks.
create() will automatically save, so even if you fix your error - you will still have to make sure the arguments to create fulfill the database requirements to save a record.
save() method is executed whenever an instance of a particular model is created either from admin interface or shell, save() method is run. You can override save() function before storing the data in the database to add new data or remove some data to be stored in a database.
Creating objects To create an object, instantiate it using keyword arguments to the model class, then call save() to save it to the database. This performs an INSERT SQL statement behind the scenes. Django doesn't hit the database until you explicitly call save() . The save() method has no return value.
No save()
does not need to be called after create()
.
from the docs for create:
A convenience method for creating an object and saving it all in one step
its to be used in place of creating an object the normal way then saving with object.save()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With