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 ''