【发布时间】:2011-03-26 19:30:58
【问题描述】:
我是 FeinCMS 的新手,我正在尝试创建自己的内容类型。这使用了我创建的另一种自定义内容类型。
在下面的代码中,“CollapsiblePanel”不会显示在管理员中,因为我只希望您能够从 ContentBox 部分创建“CollapsiblePanel”。
您还可以为每个 ContentBox 创建多个 CollapsiblePanel。我无法弄清楚如何将它们连接在一起,因此管理员允许您在 ContentBox 中添加 CollapsiblePanels
class CollapsiblePanel(models.Model):
title = models.CharField(max_length=255)
content = models.TextField()
def render(self, **kwargs):
return render_to_string('collapsiblepanel.django.html', {
'media': self,
'title': mark_safe(self.title),
'text': mark_safe(self.content),
})
class ContentBoxMedia(RichTextContent):
title = models.CharField(_('title'), max_length=200, blank=True)
collapsible = models.BooleanField()
collapsiblePanels = models.ForeignKey(CollapsiblePanel)
class Meta:
abstract = True
verbose_name = 'Content Box'
verbose_name_plural = 'Content Box'
def render(self, **kwargs):
return render_to_string('contentbox.django.html', {
'media': self,
'title': mark_safe(self.title),
'text': mark_safe(self.text),
})
【问题讨论】:
-
这段代码似乎有两个问题。首先, CollapsiblePanel 的 ForeignKey 可能是错误的——从你的描述来看,它应该是相反的。其次,不能在内联内使用内联编辑——stock Django 不允许这样做,因此 FeinCMS 也不允许。
-
哈哈;正如我刚才在回答中所解释的那样......嗨,马蒂亚斯 :)
标签: django content-management-system django-admin feincms