通过不使用crontab的脚本更新django cms数据库条目

时间:2014-11-08 01:39:57

标签: python django-models ckeditor crontab django-cms

我有一个python脚本,可以自动更新djangocms_text_ckeditor_text表的数据库条目。我在debian wheezy上使用djangocms 3。从带有trutty:~$ ./update.py的bash运行此脚本时,它可以工作,数据库条目也会更新。但是,当使用cronjob(在crontab -e -u trutty中指定)运行相同的脚本时,尽管脚本运行,但该条目不会更新。

我的脚本如下所示:

#!/home/trutty/v/bin/python
...
from django import settings
from djangocms_text_ckeditor.models import Text
from cms.models.pluginmodel import CMSPlugin
...
c = CMSPlugin.objects.filter(placeholder_id=8, parent_id__isnull=True)
if c:
    t = Text.objects.get(pk=c.first().id)
    t.body = ...
    t.save()
    ...

我错过了什么?

1 个答案:

答案 0 :(得分:0)

我现在获取页面对象并在t.save()之后立即保存。

from cms.models.pagemodel import Page
...
p = Page.objects,get(...)
...
t.save()
p.save()