Custom AdminSite and urlresolvers.reverse

48 views
Skip to first unread message

cyrus

unread,
Apr 5, 2012, 4:14:39 AM4/5/12
to django...@googlegroups.com
Hello,

We have implemented three different ModelAdmin sub-classes for the same model, registered under three different AdminSites. Nothing fancy there, only some business logic was implemented differently. After we upgraded from Django 1.2.3 to Django 1.4 these model admins started to fail on the change forms when using the save action with the following error:

Reverse for '<app_label>_<model_name>_changelist' with arguments '()' and keyword arguments '{}' not found.

The admin site was initialized with a different name and app_name:

admin_site = admin.AdminSite("my_custom_admin", "my_custom_admin")

class MyModelAdmin(admin.ModelAdmin):
    # some small configurations for change_view, static files, permissions e.t.c.

admin_site.register(MyModel, MyModelAdmin)

After digging into the following line in django/contrib/admin/options.py:847

def response_change(self, request, obj):
        # ...
        else:
            # ...
            if self.has_change_permission(request, None):
->              post_url = reverse('admin:%s_%s_changelist' %
                                   (opts.app_label, module_name),
                                   current_app=self.admin_site.name)
            else:
                post_url = reverse('admin:index',
                                   current_app=self.admin_site.name)
            return HttpResponseRedirect(post_url)

As you can see the admin namespace is hardcoded into the reverse expression. If I do the lookup with my_custom_admin:<app_label>_<model_name>_changelist it works as expected. 

I'm I doing something wrong? Was this an issue in Django 1.2 that got fixed or this is a bug in the admin app?

P.S.: Everything was working well on Django 1.2.x until we upgraded to Django 1.4. Because of this I'm not sure in which version exactly this problem appeared. 

Thanks,
Ion
Reply all
Reply to author
Forward
0 new messages