我有一个外部应用程序,其模型如下:
class Society(models.Model):
name = models.CharField(max_length=200)
class Office(models.Model):
society = models.ForeignKey(Society)
name = models.CharField(max_length=200)
我需要,每次创建和保存Office时,都会自动创建一个带有办公室名称的页面。 我正在考虑在Office上的def存储模型(models.Model),插入一个cms.api create_page, 但我无法做到这一点。有人可以帮帮我吗?
答案 0 :(得分:1)
喜欢这样吗?
import cms
parent_page = Page.objects.get(pk=1) # you will want something more valid than this
approval_user = User.objects.get(pk=1) # again, just selecting the first user,
# do something better
# like maybe the current request.user?
try:
page = create_page(title=office.name,
template=cms.constants.TEMPLATE_INHERITANCE_MAGIC,
language='en',
parent=parent_page,
published=True) # May not want to auto publish?
except Exception, err:
pass
# need some handling if the creation fails