[Django]-How to detect update in a django admin form validator

4👍

There’s no need to do this: if you set unique_together in your model’s Meta class, the admin will automatically validate that no other instance exists with the same combination.

However, to answer the general question, the way to tell if this is an update is to check that self.instance exists and has a value for the pk field.

if hasattr(self, 'instance') and self.instance.pk is not None:
    #update
else:
    #new

Leave a comment