How to solve Django custom admin site NoReverseMatch when registering models?

Viewed 106

I want to create a custom Admin site for one of the apps in my Django project. This app has a couple of models that I want to register on the admin site. The thing is that if I register all the models of the app in this custom Admin site, I get the following error:

NoReverseMatch at /admin/auto-harvest/
Reverse for 'app_list' with keyword arguments '{'app_label': 'my_app'}' not found. 1 pattern(s) tried: ['admin/(?P<app_label>auth|django_mfa|axes)/$']

However, if I register all models but except the last one, I don't get the error, and the admin site loads successfully with the exception that one of the models is not registered. I found this behavior very peculiar and can't figure out the reason. Below is my admin.py and the urls.py

class MyAdminSite(AdminSite):
    site_header = "My Admin"
    site_title = "My Admin Site"


my_admin_site = MyAdminSite(name='auto_harvest')

Registering models:

@admin.register(MyModel1, site=my_admin_site)
class MyModel1Admin(VersionAdmin):
    ...

@admin.register(MyModel2, site=my_admin_site)
class MyModel2Admin(VersionAdmin):
    ...

In the project urls I have:

urlpatterns = [
    path('admin/my-site/', include(myapp.urls)),
]

In myapp.urls I have:

urlpatterns = [
    path('', my_admin_site.urls),
]
0 Answers
Related