【问题标题】:Django - Execute a function after saving my object in the Admin templateDjango - 在管理模板中保存我的对象后执行一个函数
【发布时间】:2016-03-10 09:03:44
【问题描述】:

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

【问题讨论】:

标签: python django django-models get save


【解决方案1】:

你的答案在这里: https://docs.djangoproject.com/es/1.9/ref/signals/#django.db.models.signals.post_save

Django 有“信号”机制,在某些内部事件发生后触发注册函数。

【讨论】:

  • 非常感谢!
猜你喜欢
  • 2011-06-05
  • 2012-07-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-04
  • 2021-12-29
  • 2011-11-05
相关资源
最近更新 更多