I am very new to django CMS, I am trying to add toolbar
of my blog.
This is my cms_toolbar.py
file
from cms.toolbar_base import CMSToolbar
from cms.toolbar_pool import toolbar_pool
from blog.models import BlogPluginModel
from cms.utils.urlutils import admin_reverse
class PollToolbar(CMSToolbar):
def populate(self):
menu = self.toolbar.get_or_create_menu(
'blog_pluginmodel', # a unique key for this menu
'blog', # the text that should appear in the menu
)
menu.add_modal_item(
name='Add a new blog', # name of the new menu item
url=admin_reverse('blog_pluginmodel'), # the URL it should open with
)
toolbar_pool.register(PollToolbar)
But fires me an error below:
NoReverseMatch at /en/
Reverse for 'blog_pluginmodel' not found. 'blog_pluginmodel' is not a valid view function or pattern name.
I am not getting how can i fix this.. Can anyone help me in this case?
What is reverse-admin actually?
Here's a link to the documentation, and here's the source code.
What admin_reverse
does is resolve the admin (list/add/edit) view of a django model to display it in the djangocms modal.
In your case, something like this should work:
admin_reverse('blog_pluginmodel_changelist')
or
admin_reverse('blog_pluginmodel_add')
In a more abstract way: reverse_admin('appname_modelname_adminview')
.
P.S.: I'm not sure if a plugin model is really what you want to make accessible through the toolbar, but that's another discussion.