我正在製作一個django應用程序。要根據行和註釋計算提要的排名,我正在嘗試使用django-background-tasks。我在節點模型中使用的功能是:如何使用django-background-tasks
@background(schedule=60)
def get_score(self):
p = self.likes+self.comments # popularity
t = (now()-self.date).total_seconds()/3600 # age_in_hrs
# last_activity =
n = self.admin_score
score = (p/pow((t+1), 1.2))*n
self.score = score
return score
但是我沒有看到任何分數變化。這意味着我正在以正確的方式做,而我錯過了基本概念。有人可以告訴我如何使用django-background-tasks來安排任務或將我引用到一些現有的文檔。
好吧,這意味着我不能在模型或視圖本身中安排任務 – Rohit
@Rohit我認爲你可以在'models.py'(單獨的文件僅僅是來自文檔的建議)內部保留這個方法,但是作爲具有'id '作爲參數導致任務參數以db的json格式存儲,所以你不能傳遞你的對象,因爲它以後不能再從json中重現。 – bellum
當我運行python manage.py process_tasks,我得到這個錯誤: C:\ Python34 \ LIB \站點包\ background_task \ models.py:28:RemovedInDjango18War 寧:'Manager.get_query_set'方法應該改名 'get_queryset'。 類任務管理器(models.Manager): 未知命令: 'process_tasks' 我是什麼在這裏失蹤 – Rohit