I have a Section with a header and its displayed even if the Section has no child views. How can I automatically hide the Section if it does not have any child views?
Section(header: Text("Header")) {
// No child views
}
Related
There are some custom menu items in the admin's menu, it is easy to order them (the items marked in red below).
Just set menu_order of the custom ModelAdmin object.
The question is how to reorder the built-in menu items, such as Pages, Images, Media, and Settings.
You can use the construct_main_menu hook to modify existing menu items.
For example, to move the Pages item to the bottom, place this code in a wagtail_hooks.py file within one of your apps:
from wagtail import hooks
#hooks.register('construct_main_menu')
def reorder_menu_items(request, menu_items):
for item in menu_items:
if item.name == 'explorer': # internal name for the Pages menu item
item.order = 100000
break
I've defined the following custom widget in forms.py, which over rides the standard HTML to create a "live search" select menu (user can enter free text to search options, useful when there are many options). For this widget to work, the class="selectpicker" class must be applied. How do I apply this class at the widget level?
class LiveSelectWidget(forms.widgets.Select):
template_name = "widgets/live_select.html"
option_template_name = 'widgets/live_select_option.html'
I have the following setup right now:
class MyView(MyPermission1, MyPermission2, FormView):
...
class MyChildView(MyView):
...
The child view is inheriting from the parent, but I want to remove MyPermission1 and MyPermission2 from it and apply another class called MyPermissionChild. Is there a way to do this using the generic views available in Django?
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?
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.
I have the following form with radioselect options :
jobStatus = forms.ChoiceField( widget=forms.RadioSelect())
However, it renders the radio buttons in <ul> <li> .. </li></ul> tags.
Could you suggest me any way to render the only radiobutton input ?
Thanks
This is a nice how-to for overriding the renderer of the radio select widget.
https://wikis.utexas.edu/display/~bm6432/Django-Modifying+RadioSelect+Widget+to+have+horizontal+buttons
Basically, create a class that inherits from the forms.RadioFieldRenderer class and override the render method. Then in your form when setting the widget use the renderer argument to set the renderer to your custom renderer class.
That being said, I usually just change the appearance using CSS