2

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()
BrianCas
  • 749
  • 3
  • 12
  • 22
  • duplicate of this question: http://stackoverflow.com/questions/30252693/django-admin-call-function-on-save which also has a better answer – lsh Apr 18 '17 at 03:46

1 Answers1

1

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.