自定义链接插件

问题描述:

我目前正在构建一个多站点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 '' 

我想我已经找到了答案:https://*.com/a/5700886/378136

我建议保留这一职位,以帮助别人使用相同的查询。