Add a custom category and admin page for a non-model view in Mezzanine

I need to add a custom view to Mezzanine admin, which is statistics and dashboard not supported by the model, but api calls.

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

+3


source to share


1 answer


I did a similar thing where I wanted to add a jqGrid report to the admin interface. It was a report on existing data (custom product view), so it didn't have its own model. This functionality is largely built into the Mezzanine framework with just a few add-ons.

To display a menu item 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 following items are part of the default cartridge settings, except for the Product Report section. By placing a tuple instead of a model name, the first item becomes the name of the menu item and the second becomes the name of the view being used.

("Product Report", "jqgrid_sample_view")



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

In my case, the goal was to show the jqGrid using jdqGrid , but you can adapt it to any kind 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.

0


source







All Articles