How to reorder Wagtail admin menu items - django

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

Related

How can I fix the paginator and the filter problem for Django?

To simply explain, I have a model product with columns:
(Product model):
name
type
(Order model):
order
price
quantity
I am using the django built-in Paginator and the django-filter.
The paginator works so well and it really filters the items but the problem is, when the paginator is involved, the "Next" or "Previous" button I created will not work well to see the filtered items on the next or previous page because it reloads the whole template and the filter form will be erased.
Example:
I have mouse and keyboard as "choices" on the "Type" column of the product. I have 25 mice, and the paginator divides it by 10. I can filter the items and shows 3 pages for the mice but when I turn to the next page, the keyboard items will show because the filter form is reset. Any help or suggestion will be appreciated. I need to hear any thoughts for this.

How do I disable the update button on View Cart for specific product categories in OpenCart

I have an OpenCart site and would like to disable the update button in the View Cart page for products belonging to a specific category. If the products don't belong to the category, the update button will be enabled.
You can add a column in the database then add supporting code to the admin/controller, admin/template, catalog/controller, catalog/view/theme/yourtemplate. Then you can wrap the view cart button in your catalog/view/theme/yourtemplate/product/product.tpl with a PHP IF exists statement.
Just an example. Good luck!

Add Custom Admin Category and Page for non-model view in Mezzanine

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.

Django admin, override dropdown with selection from popup window

In a one-to-many relationship, how can I override the drop-down menu in the change-form to be able to select value from popup window, specially when dropdown could hold a pretty long list which may slowdown the page load.
Just found the answer:
raw_id_fields is a list of fields you would like to change into an
Input widget for either a ForeignKey or ManyToManyField:
class ArticleAdmin(admin.ModelAdmin):
raw_id_fields = ("newspaper",)
https://docs.djangoproject.com/en/1.6/ref/contrib/admin/#django.contrib.admin.ModelAdmin.raw_id_fields
The question now is how can I display a user friendly value instead of the Id returned from the popup.

django admin inlines (and nested inlines) : how can I get this functionality?

I'm a little confused as to why this sort of functionality isn't default in the admin, but maybe someone can give me a few hinters to how to go about it.
I have a projects application which keeps track of projects and is to be edited through the admin. Each project has numerous ForeignKey related models (links, flatpages, video, image etc.) that could be placed as inlines within the project admin.
(One or two models have nested inlines, so they don't display in the admin (this and this ticket deal with this) )
Instead of being able to edit these models inline on the project admin (which gets messy and difficult to use), I would love a list of all the current instances of that related model, and simple add/edit button for each model which opens a popup with that model's form.
Project Admin:
- Normal Fields
- Links:
-Link 1 (edit)
-Link 2 (edit)
+ add link <- popup
- Images:
-Image 1 (edit)
-Image 2 (edit)
+ add image <- popup
so on. How would I go about writing this? I only need to do it for one section/model of the admin panel so I don't think writing my own Crud backend is necessary.
Thanks
I implemented something like this in an application once, but since django-admin doesnt support nested inlines (by which i mean inlines within inlines), i followed a slightly different approach. The use case was that you had an invoice (with a few inline attributes) and u had reciepts (again with inline attributes). Reciepts had a foreign key to the invoice model (basically a reciept was part payment of the invoice).
I implemented it by adding a field to the invoice list view which linked to a filtered reciept list view.
So in the invoice admin, there would be:
def admin_view_receipts(self, object):
url = urlresolvers.reverse('admin:invoice_%s_changelist'%'receipt')
params = urllib.urlencode({'invoice__id__exact': object.id})
return 'Receipts' % (url, params)
admin_view_receipts.allow_tags = True
admin_view_receipts.short_description = 'Receipts'
This gives you a link in the list view that takes you to another list view, but filtered by foreignkey. Now you can have inlines for both models and easy access to the related models.