You seem to have a bit of confusion over what it means to instantiate an object. It has nothing whatever to do with the database. This instantiates a model object without saving it to the database, in which case its pk will be None:
and this (indirectly) instantiates an object by getting it from the database:
post_init signal will be sent in both of these cases, even though neither of them has anything to do with saving to the database.
If you want something to happen when you save, either override the
save method itself, or use the
post_save signals. You can check there whether or not the object has been previously saved, by verifying if its
pk is None.
I know the question is old but I had a similar problem and easy solution for that is just using post_save signal and check if created
def when_init(sender, instance, created, **kwargs):
- How can I test if gunicorn is working and communicating with nginx?
- Registered models do not show up in admin
- Writable nested serializer in django-rest-framework?
- Drf-spectacular is using the wrong AutoSchema to generate Swagger