Search code examples
djangodjango-cmsdivio

How to create sub-pages for apphook model instances with django-cms?


Question Context

I am responsible to design the cms architecture for a project.

The requirements state that a group of editors should be able to create "Projects".

Each project..

  • saves meta data about itself
  • is queryable from other places (e.g. top 5 projects).
  • has a page that displays information about it. (does not need to be a cms page instance)
  • can be connected to countries (meaning that an implementation of that project exists in the selected counties).
  • can have sub-pages which in turn can also be nested.

Imagined Example

Using the django-cms documentation as a bases I would image the resulting structure to look like this:

  • Projects (apphook)
    • "Project 1" (Page for project 1 model instance)
    • "Project 2" (Page for project 2 model instance)
      • "Project 2 Subpage 1" (Subpage for project 2 model instance)
      • "Project 2 Subpage 2" (Subpage for project 2 model instance)
        • "Project 2 Sub-Subpage" (Subpage of "Project 2 Subpage 2")

However that does not seem to exist or at least I did not see any references on how to get such a structure.

In a video I heard that as soon as there is an apphook.. subpages do not make sense anymore. Somewhere else I read that in theory if the hook is permissive enough.. it could be combined. However even if that works.. the subpages would not be liked to actual instances of the custom apphook model.

PS: I am currently using: django-cms==3.3.0

Question

How can I feature such a structure using django-cms?

I figured it could be done by having an apphooked page for each project. In that case.. the server would have to be restarted for every newly created project. That does not seem to be very elegant.

Alternatives

I have been working with wagtail on a previous project. Thus I do know how to implement such a structure with wagtail easily using ProjectPage and ProjectSubpage models. I refuse to give up on django-cms being capable of replicating such functionality. I am open for alternative paradigms and approaches. Maybe there are some I have not thought of. If so please let me know. :)

Request

Guidance and ideas are very welcome! Please tell me if you know of any way how to get that or have some idea that could point me in the right direction.

Thank you!


Solution

  • A couple of points here for you.

    1. django CMS can happily serve pages "beneath" and apphook, but the apphook gets priority during URL resolution. So, just make sure that your apphook's URL patterns don't gobble up everything and sub-pages should be OK.

    2. An alternative approach would be to make a one-to-many table that holds "page-like" attributes (title, meta-attributes, etc.) and at least one PlaceholderField. This can then be used to present what appears to be normal CMS pages that the apphook-itself can control with its views. So, you could have apphook-model-specific context and url-patterns and still have almost all of the front-end editing features of the CMS.

    I hope this helps!