WagtailWagtail

How to Use ModelAdmin with Wagtail CMS v6+

Apr 29, 2024 · by Tim Kamanin

The powerful ModelAdmin feature of Wagtail CMS has been removed as of Wagtail v6. The Wagtail team now encourages the use of SnippetViewSet, which includes advanced features like bulk actions. Here is an official migration guide from ModelAdmin to Snippets.

However, if you have extensive custom code reliant on ModelAdmin, or numerous ModelAdmin instances, and find that migrating them to SnippetViewSet would be time-consuming (a common issue in one of the projects I maintain), it doesn't mean you can't upgrade to Wagtail v6. ModelAdmin has been spun off from Wagtail CMS into a separate package called wagtail-modeladmin.

Thus, if you upgrade to Wagtail v6 and encounter error messages such as: ModuleNotFoundError: No module named 'wagtail.contrib.modeladmin', do not worry. Simply follow these steps to switch from deprecated wagtail.contrib.modeladmin to wagtail-modeladmin:

  1. Install the wagtail-modeladmin package:

    python -m pip install wagtail-modeladmin
    

  2. Add wagtail_modeladmin to the INSTALLED_APPS in your settings.py file:

    INSTALLED_APPS = [
        # ...
        "wagtail_modeladmin",
        # ...
    ]
    

  3. Replace all occurrences of wagtail.contrib.modeladmin with wagtail_modeladmin in the .py files within your Python project. Use your editor’s "Find and Replace" feature to make this change efficiently.

By following these steps, you should have successfully transitioned to using wagtail-modeladmin. This will give you ample time to plan a migration to SnippetViewSet as needed.

Hey, if you've found this useful, please share the post to help other folks find it:

There's even more:

Subscribe for updates

  • via Twitter: @timonweb
  • old school RSS:
  • or evergreen email ↓ ↓ ↓