I am building custom AdminModels based on Wagtail Snippets and have a custom menu in the AdminPanel for my models. How do I hide/remove the Snippet selection from AdminPanel without disabling? Thank you.
@register_snippet tells Wagtail to treat the model as a snippet. The panels list defines the fields to show on the snippet editing page. It’s also important to provide a string representation of the class through def __str__ (self): so that the snippet objects make sense when listed in the Wagtail admin.
Today, let's have a look at how we can customize the admin panels in a Wagtail site. To make the fields appear in the admin interface, they need to be added to one of the panels. You can also make the panel collapsed by default by adding the class name collapsed. For a field panel, I also added the classes full and title to the FieldPanel.
By default, panels are formatted as inset fields. The CSS class full can be used to format the panel so it covers the full width of the Wagtail page editor. The CSS class title can be used to give the field a larger text size, suitable for representing page titles and section headings.
class wagtail.admin.panels.InlinePanel(relation_name, panels=None, classname='', heading='', label='', help_text='', min_num=None, max_num=None) ¶ This panel allows for the creation of a “cluster” of related objects over a join to a separate model, such as a list of related links or slides to an image carousel.
Since item.name
in menu_items
can be blank, better solution is:
from wagtail.snippets.wagtail_hooks import SnippetsMenuItem
@hooks.register('construct_main_menu')
def hide_snippets_menu_item(request, menu_items):
menu_items[:] = [item for item in menu_items if not isinstance(item, SnippetsMenuItem)]
Put the following hook into wagtail_hooks.py file of your Wagtail CMS app:
from wagtail.wagtailcore import hooks
@hooks.register('construct_main_menu')
def hide_snippets_menu_item(request, menu_items):
menu_items[:] = [item for item in menu_items if item.name != 'snippets']
And you're basically done! You can use this approach to hide any item from the admin menu.
I described it recently on my blog: http://timonweb.com/posts/how-to-remove-snippets-menu-item-from-wagtail-cms-admin-menu/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With