3

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.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),
       })
Paolo
  • 20,112
  • 21
  • 72
  • 113
Jeremy
  • 31
  • 1
  • It seems there are two problems with this code. First, the ForeignKey to CollapsiblePanel is probably wrong -- it should be the other way around judging from your description. Second, it's not possible to use inline editing inside inlines -- stock Django does not allow this, therefore FeinCMS does not either. – Matthias Kestenholz Mar 26 '11 at 20:18
  • Ha ha; as I explained in my answer just now... Hi Matthias :) – DrMeers Mar 26 '11 at 20:37

1 Answers1

2

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).

DrMeers
  • 4,117
  • 2
  • 36
  • 38
  • Thank you for your replies. Here is what I came up with, but now I'm having a rendering issue. [Pastebin Code](http://pastebin.com/wC58qgy0) The rendering issue is the fact that feincms won't render what I select from the dropdown. I'm unsure what my render function should look like. – Jeremy Mar 27 '11 at 22:55
  • Could you provide a simple example of how I would us this? [Base.content_type_for](http://www.feinheit.ch/media/labs/feincms/contenttypes.html#obtaining-a-concrete-content-type-model) – Jeremy Mar 28 '11 at 00:04
  • It's a link to the documentation, which has a simple usage example. `x = MyBaseModel.content_type_for(ContentBoxMedia)` then `admin.site.register(x)` or similar. But don't waste time on it unless you're pretty sure you understand what it entails. Your updated example model doesn't seem to be abstract, which means it can't be used as a FeinCMS content type anyway. – DrMeers Mar 28 '11 at 04:35