1

我目前正在构建一个多站点 Django 网站。我希望能够覆盖基本链接插件的功能,cms.plugins.link以便能够链接到任何其他站点中的任何其他页面。

我正在使用默认编辑器WYMeditor

我已经创建了一个自定义 CMSPlugin 抽象模型,它通过使用cms.models.fields.PageField该类提供了我需要的功能,并在定制插件中使用它。

我不确定的是如何(或是否)我可以更改现有cms.plugins.link模型或以某种方式扩展它。我需要在一个简单实例中的可用插件列表中提供这个修改后的插件。cms.plugins.text

对于它的价值,我的自定义插件的代码如下:

class PluginWithLinks(models.Model):
    """
    There are a number of plugins which use links to other on-site or off-site
    pages or offsite. This information is abstracted out here. Simply extend
    this class if you need a class which has links as a core part of its
    functionality.
    """
    page_link = PageField(
        verbose_name="page",
        help_text="Select an existing page to link to.",
        blank=True,
        null=True
    )
    url = models.CharField(
        "link", max_length=255, blank=True, null=True,
        help_text="Destination URL. If chosen, this will be used instead of \
the page link. Must include http://")
    link_text = models.CharField(
        blank=True, null=True, max_length=100, default='More', help_text='The \
link text to be displayed.')
    target = models.CharField(
        "target", blank=True, max_length=100,
        choices=((
            ("", "same window"),
            ("_blank", "new window"),
            ("_parent", "parent window"),
            ("_top", "topmost frame"),
        ))
    )

    class Meta:
        abstract = True

    @property
    def link(self):
        if self.url:
            return self.url
        elif self.page_link:
            full_url = "http://%s%s" % (
                self.page_link.site.domain,
                self.page_link.get_absolute_url()
            )
            return full_url
        else:
            return ''
4

0 回答 0