Django: how can I tell if the post_save signal triggers on a new object?
Have a look at docs: https://docs.djangoproject.com/en/stable/ref/signals/#post-save
There is a created
named argument which will be set to True
if it's a new object.
As Docs stated and @seler pointed out, but with an example:
def keep_track_save(sender, instance, created, **kwargs):
action = 'save' if created else 'update'
save_duplicate((instance.id, instance.__class__.__name__, action))
post_save.connect(keep_track_save, sender=Group)