这里是菜鸟。 我试图在从管理面板保存(单击“保存”)对象后立即执行功能, 我尝试了 get_or_create,但我不知道如何使其工作
这是我的代码(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()
最佳答案
你的答案在这里: https://docs.djangoproject.com/es/1.9/ref/signals/#django.db.models.signals.post_save
Django 有“信号”机制,在某些内部事件发生后触发注册的函数。
关于python - Django - 在管理模板中保存我的对象后执行函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35911836/