BrianCas
BrianCas

Reputation: 789

Django - Execute a function after saving my object in the Admin template

noob here. Im trying to execute a function right after I save (click save) an object from the Admin Panel, I tried get_or_create, but I can't figure it out how to make it work

Here is my code (models.py)

#The function creates a group of folders
def Create_Space():
    queuepath = r"C:\Users\BrianC\Desktop\DjangoPrueba\prueba6\queue"
    acceptedpath = r"C:\Users\BrianC\Desktop\DjangoPrueba\prueba6\accepted"
    if not os.path.exists(queuepath) and not os.path.exists(acceptedpath) :
        os.makedirs(queuepath)
        os.makedirs(acceptedpath)


#Here is the model
class Espacio (models.Model):

    prom_name = models.CharField(max_length=30, null=False)
    prom_email = models.EmailField(max_length=254, null=True)
    phone_contact = models.BigIntegerField(max_length=50, null=False)
    school_name = models.CharField(max_length=30, null=False)
    school_phone = models.BigIntegerField(max_length=50, null=False)
    school_address = models.TextField(null=False)
    other_details = models.TextField()

Upvotes: 2

Views: 1741

Answers (1)

Konstanty Karagiorgis
Konstanty Karagiorgis

Reputation: 93

Your answer is here: https://docs.djangoproject.com/es/1.9/ref/signals/#django.db.models.signals.post_save

Django has "signals" mechanism, that triggers registered functions after certain internal events occur.

Upvotes: 1

Related Questions