我有一个ListView,我想在python中执行一个脚本,每次进入listview时都会更新我们的数据库,或定期。
有办法吗?
class AccessPointList(generic.ListView): #receives the whole set of AccessPoint and send to HTML
model = AccessPoint
#call a function in python -> c.update()
#or create a def to update our database
答案 0 :(得分:2)
当然,只需要在运行它时覆盖其中一个方法,然后调用super继续正常执行ListView
class AccessPointList(generic.ListView):
model = AccessPoint
def get(self, request, *args, **kwargs):
# call your function
return super().get(request, *args, **kwargs)