Django Admin: How do I know when a user is editing an existing object or saving a new object?

I would like to learn how to work with Django admin. How do I know when a user is editing an existing object or saving a new object?

For example, if I want a function to do something different when the user saves a new object or saves an edited object, how do I know what it is?

Thanks guys:)

Sorry for my English.

+2


source to share


2 answers


class MyModel(models.Model):

    def save(self):
        if self.id != None:
            print "Edited object"
        else:
            print "New object"
        super(MyModel, self).save()

      



+6


source


Perhaps you could do one of the following:



+1


source







All Articles