3

I need to add a custom view to the Mezzanine admin, which is a stats and reporting dashboard that is not backed by a model, but api calls.

I have the following questions: 1. Where do I add the custom module? Should this be under the /theme directory with in my app or in the root of the app itself? 2. How do I register this module to display the view from the left sidebar navigation menu?

activelogic
  • 1,325
  • 3
  • 14
  • 24

1 Answers1

0

I did a similar thing where I wanted to add a jqGrid report to the admin interface. This was a report of existing data (a custom product view) so it didn't have it's own model. This functionality is pretty much built into the Mezzanine framework with just a few additions.

To get the menu item to show up in the left hand menu, it needs to be added as ADMIN_MENU_ORDER in settings.py.

ADMIN_MENU_ORDER = (
    ("Content", ("pages.Page", "blog.BlogPost", "generic.ThreadedComment", ("Media Library", "fb_browse"))),
    (("Shop"), ("shop.Product", "shop.ProductOption", "shop.DiscountCode", "shop.Sale", "shop.Order",("Product Report", "product_report_view"))),
    ("Site", ("sites.Site", "redirects.Redirect", "conf.Setting")),
    ("Users", ("auth.User", "auth.Group")),
)

All of the items below are part of the default cartridge settings except the "Product Report" section. By putting a tuple instead of just a model name, the first element becomes the name of the menu item and the second is the name of the view that is used.

("Product Report", "jqgrid_sample_view")

If you use a model name (such as "shop.Product", then the shop.Product model is used and the name of the model is used as the menu item.

In my case, the view's purpose was to render a jqGrid using jdqGrid but you can adapt this to whatever view you want.

def jqgrid_sample_view(request):
    grid = ProductGrid
    request.grid = grid
    return render(request, 'product_report.html', {'grid': grid})

The HTML generated by the view is inserted into the content area of the Mezzanine admin page when the "Product Report" link is clicked.

andrewmo
  • 1,922
  • 1
  • 17
  • 20