[英]How to automatically change a Django Model field after a specific amount of time?
[英]Best way to change a django model field automatically after a certain amount of time?
我正在創建類似托管的服務,我需要向客戶發送電子郵件,以便他們在購買后的一段時間后驗證他們是否收到了 package。 我有一個帶有“funds_unlocked”boolean 屬性的訂單 class。 如果客戶對他的產品感到滿意(也就是他將其設置為 TRUE),或者如果在 2 周 go 之后客戶沒有回復,則只能將其設置為 TRUE。 然后“funds_unlocked”屬性自動設置為 TRUE 並且供應商的帳戶余額增加。 如何自動向客戶發送電子郵件並在 2 周后自動將字段更改為 TRUE?
class Order(models.Model):
funds_unlocked = models.BooleanField(default=False)
def save(self, *args, **kwargs):
// if (old order funds_unlocked = False) and (new order funds_unlocked = True):
// increase Balance of vendor
除了使用 celery 之外,還有其他/更簡單的方法嗎? 你會怎么做?
提前致謝
您可以使用 celery 創建一個定期任務,每天或每小時檢查滿足此要求的條目,更新它並發送 email:
https://django-celery-beat.readthedocs.io/en/latest/index.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.