0

我有一个外部应用程序,其模型如下:

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(models.Model)上的def save-model,插入一个cms.api create_page,但我无法完成它。任何人都可以帮助我吗?

4

1 回答 1

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
于 2013-07-14T18:44:03.600 回答