After saving a model, shouldn't the model refresh from db?
No, it is not refreshed. It simply makes an CREATE
or INSERT INTO
statement at the database. So here it will look like:
INSERT INTO appname_test_model (field) VALUES ('{"test": 5}');
That is all, the object remains the same. In fact if you for example have a DecimalField
and you assign it an int
, it will still remain an int
.
If the primary key is an AutoField
(or a BigAutoField
), it will also set the primary key of the object the first time it saves that object:
As specified in Saving objects section of the documentation:
To save an object back to the database, call save()
.
(…)
The model save process also has some subtleties; see the sections below.
Auto-incrementing primary keys
If a model has an AutoField
— an auto-incrementing primary key — then that auto-incremented value will be calculated and saved as an attribute on your object the first time you call save()
.