Paritosh Singh
Paritosh Singh

Reputation: 6404

Django: call a function after a model is saved

What I am trying to do is execute a function after model is saved. For eg: when I upload a db dump file through admin, i want to load it that time to db.

I tried following thing by overriding save function:

class DumpFile(models.Model)
 file = models.FileField(upload_to="dump")
 def save():
  super(models.Model,self).save()
  <LOAD DUMP  LOGIC>

Here it is giving attribute error super has no attribute save(). I don't understand what is the problem there. Please let me know this problem or about any function which works after models are saved.

Upvotes: 0

Views: 5025

Answers (1)

Ned Batchelder
Ned Batchelder

Reputation: 375932

super is supposed to be given the current class, not the parent class:

super(DumpFile, self).save()

Also, look into signals, which are another mechanism for making things happen after standard Django events.

Upvotes: 4

Related Questions