Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8804309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:34:11+00:00 2026-06-14T01:34:11+00:00

I’m working on a project and I need to be able to programatically inject

  • 0

I’m working on a project and I need to be able to programatically inject a number of application-model-based items into an existing CMS-based menu. I’ve started to use the code found here to modify the menu: http://docs.django-cms.org/en/2.3.3/extending_cms/app_integration.html.

EDIT: Much more detail

My client would like me to attach application-model objects to the CMS menu so that they are children of an existing CMS page in the menu. I currently have a total hack in place which requires me to make fake pages in the CMS that are children of the desired menu item, have the same name as the application-model objects, then, I’ve installed a Modifier like so:

class SportsMenuModifier(Modifier):
  def modify(self, request, nodes, namespace, root_id, post_cut, breadcrumb):
    if post_cut:
      return nodes

    for node in nodes:
      if node.title == "Baseball":
        node.url = "/sports/baseball"
      elif node.title == "Football":
        node.url = "/sports/Football"
      elif node.title == "Bowling":
        node.url = "/sports/bowling"
      elif node.title == "Golf":
        node.url = "/sports/golf"

    return nodes

menu_pool.register_modifier(SportsMenuModifier)

There is so much wrong with this I don’t know where to begin, but I’ll use this non-exhaustive list to highlight some of the most basic issues:

  • Requires the presence of “Fake” CMS pages
  • Ridiculously dependent on the naming of the application sports objects and the fake pages
  • Will
    not detect when the customer creates new sports objects
  • Very confusing for everyone involved

What I was hoping I could do was something like this (WILL NOT WORK):

in models.py

from django.db import models
from cms.models.pagemodel import Page

class Sport(models.Model):
  name = models.CharField(...)
  parent = modes.ForeignKey(Page, ...)
  ...

in menu.py

class SportsMenu(Menu):
  def get_nodes(self, request):
    nodes = []

    for sport in Sports.objects.filter(...).order_by('order'):
      node = NavigationNode(
        _(sport.name),
        sport.get_absolute_url(),
        sport.pk,
        sport.parent.pk
      )
      nodes.append(node)

    return nodes

menu_pool.register_menu(SportsMenu)

I’m not sure I can continue with this approach because:

  1. I don’t know how to fetch the menu.namespace for a given Page

  2. Even when I hard-code the namespace to “CMSMenu” (I read somewhere this is what it is), this still does nothing that I can see.

So, how do we attach application-model based objects as children to existing CMS-page-based menu items?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T01:34:12+00:00Added an answer on June 14, 2026 at 1:34 am

    The answer for this is that I should have been using (and AM using) Attach Menus which are, unfortunately, VERY poorly documented here: https://django-cms.readthedocs.org/en/latest/extending_cms/app_integration.html#attach-menus.

    Also, while I was following those instructions, I accidentally imported CMSAttachMenu from menus.base rather than from cms.menu_bases which doesn’t result in any errors, but also doesn’t do anything, so, it was rather difficult to debug =/

    Here is some working code in case it helps anyone in the future:

    in models.py

    from django.db import models
    
    class Sport(models.Model):
      name = models.CharField(max_length=64, blank=True)
      slug = models.SlugField(blank=True)
    
      def __unicode__(self):
        return self.name
    
      def get_absolute_url(self):
        return "/sports/" + self.slug
    

    In menu.py

    from cms.menu_bases import CMSAttachMenu
    from django.utils.translation import ugettext_lazy as _
    from menus.base import NavigationNode
    from menus.menu_pool import menu_pool
    
    from apps.theproject.models import Sport
    
    
    class SportSubMenu(CMSAttachMenu):
    
      name = _("Sports Sub-Menu")
    
      def get_nodes(self, request):
    
        nodes = []
        for sport in Sport.objects.order_by('order'):
          node = NavigationNode(
            sport.name,
            sport.get_absolute_url(),
            sport.pk
          )
          nodes.append(node)
    
        return nodes
    
    menu_pool.register_menu(SportSubMenu)
    

    Once these two files are in-place, restart the service. In Django-CMS, navigate to the page whose menu-item you’d like to have the various Sports object appear as children menu-items in your menu.

    In the Advanced Settings section (which is normally collapsed), you’ll see a new option “Attached Menu”, choose the new item “Sports Sub-Menu” and you’ll be in business.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am currently running into a problem where an element is coming back from
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
this is what i have right now Drawing an RSS feed into the php,
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I need a function that will clean a strings' special characters. I do NOT

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.