pythondjangodjango-modelsdjango-admindjango-modeladmin

Django "django-modeladmin-reorder" library does not work for side navigation/nav bar of admin


I have a django project, which contains several models with natural grouping, as well as some off-the-shelf models from install libraries.

I am trying to have this natural grouping reflected in the admin hope page, as well as the side navigation (nav bar) of the admin panel. By using django-modeladmin-reorder library, the home page is properly grouped as I want. Though, the nav bar ordering is not working and the models appear in their original order (alphabetically, grouped by the library/file where they are fetched from).

I have tried several complex (or more complex than just plugging a library) solutions, such as overriding the nav bar/app list html of django and create other templates and creating custom middlewares.


Solution

  • The django-modeladmin-reorder library looks like it is not maintained, with issues (e.g. the issue already raised in early 2020 for nav-bar customization) in the github repo remaining unanswered for 2 to 3 years now. This affects the nav-bar customization, which is supposedly support by the library.

    Thankfully, in the same issue, given as an example above, a user has provided their local repo for which they are handling the nav-bar functionality. Unfortunately, despite having a PR created, this is not accepted (at the time of writing this).

    If you already using the library, moving from the library to the local repo should be easy and nearly plug'n'play. All you have to do is uninstall the library that you already use for the reordering:

    pip uninstall django-modeladmin-reorder
    

    Then you can re-install it through the local report:

    pip install git+git://github.com/bloodwithmilk25/django-modeladmin-reorder.git@master
    

    If that fails you can try to change git+git to git+https:

    pip install git+https://github.com/bloodwithmilk25/django-modeladmin-reorder.git@master
    

    Then all you have to do is to re-run your server and changes should be available both in the homepage and in the nav bar.

    Disclaimer: I have no affiliation to the library or the repo of the user. I was simply trying to find a solution for a couple of days and I found this. I thought to create a question and answer it myself, to let the world know. There is no provision or expectation that the repo will be maintained properly for future version of Django and/or Python. Though, this is the best alternatively that we have now, unless someone wants a completely customize solution (which this repo can serve as a guide either way). Hopefully the user's PR will be accepted and we will be able to move back to the library.

    My custom homepage

    My ordering - Homepage

    My custom nav bar

    My ordering - Navbar