python - Django - 在管理模板中保存我的对象后执行函数

标签 python django django-models get save

这里是菜鸟。 我试图在从管理面板保存(单击“保存”)对象后立即执行功能, 我尝试了 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/

相关文章:

python - SMTP 发送优先邮件

javascript - 单击重置单选按钮尝试在 Django 中提交表单

python - Django ORM 是否定义了一个构造,它从给定表的指定列下的每一行生成表?

python - 使用推导式拆分并展平字符串和 None 值的列表

python - 如何同时运行两个 python 循环?

python - 连续调用 cProfile/pstats 无法正确更新

python - 无法在 textarea html css 中格式化文本?

python - django 中的类别-子类别下拉列表

python - Django 外键 : is it possible to ask for a name instead of an id?

python - Django 从三个表中检索数据