6👍
✅
You can check self.instance.pk
to see if the model has previously been saved. However, that could be unreliable in the case where you created a new instance of the model and then initialized a modelform with that instance before saving it.
Another possibility, based on the BaseModelForm source code in Django 1.2, is to check self.instance._adding
, which will be True if the model was created and False otherwise. However, I haven’t tested this, so YMMV.
If the first option will work, I’d recommend using that rather than an undocumented feature of ModelForms–it’s less likely to change in the future and probably clearer.
Source:stackexchange.com