0

我正在使用夹层 + 墨盒制作购物车应用程序。每当管理员将订单状态从未处理更改为已处理时,我都想调用自定义函数。

自定义功能可能包括发送邮件,添加跟踪订单号。等等

但我不知道如何仅在更改一个字段时调用此函数以及在哪里调用此函数 admin.py 或 models.py

请给我一些提示,我在哪里做了这个,它只在数据库中的一个字段发生变化时调用

4

1 回答 1

0

models.py

class MyModel(models.Model):
    ...

    def save(self):
        super(DocumentTemplate, self).save(*args, **kwargs)

        # retrieve the old version of the object
        try:
           old = DocumentTemplate.objects.get(id=self.id)
        except MyModel.DoesNotExist:
           # object is being created
           customize_function_create(self)

        # check if something has changed
        if self.interesting_field != old.interesting_field:
            # the field has been changed
            customize_function_update(self)

        return
于 2013-01-08T14:51:24.033 回答