开发者

FeinCMS admin inlines

开发者 https://www.devze.com 2023-02-19 19:02 出处:网络
I\'m new to FeinCMS and I\'m trying to create my own content type. That uses another custom content type I created.

I'm new to FeinCMS and I'm trying to create my own content type. That uses another custom content type I created.

In the code below "CollapsiblePanel" does not show in the admin as I only want you to be able to create "CollapsiblePanels" from the ContentBox section.

You can also create multiple CollapsiblePanels for each ContentBox. I'm having trouble figuring out how to wire this together so the admin allows you to add the CollapsiblePanels inside the ContentBox

class CollapsiblePanel(models.Model):
   title = models.CharField(max_length=255)
   content = models.TextField()

   def render(self, **kwargs):
       return render_to_string('collapsiblepanel.django开发者_StackOverflow.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),
       })


If you should be able to have multiple CollapsiblePanels per ContentBoxMedia, your relationships are set up the wrong way around -- the ForeignKey should be in CollapsiblePanel instead.

However it seems that what you are after is for automated handling of your CollapsiblePanel "inline"? This will not work out of the box, because FeinCMS handles all content types as inlines themselves (so ContentBoxMedia objects are already handled as inlines of the parent object), and Django does not support nested inlines.

I suspect any hack to provide such functionality would be horrendously complex; you could try to render your own formset in the ContentBoxMedia template, but you would need to hack the ItemEditor.change_view method to handle the data, which would not work easily. Alternatively you could avoid this by adopting an Ajax approach, but this would only work within saved ContentBoxMedia objects and not new ones.

Alternatively you could try to register ContentBoxMedia with admin directly so that you could use CollapsiblePanel inlines, but this would require leaving the main FeinCMS parent admin page to edit these separately. If you wanted to explore this, you would need to use Base.content_type_for and register the resultant model with your AdminSite (and of course explicitly register an inline).

0

精彩评论

暂无评论...
验证码 换一张
取 消