Opened 11 years ago

Closed 11 years ago

#20934 closed Bug (fixed)

NoReverseMatch on ModelAdmin.changelist_view if appname_modelname_change url is removed from get_urls

Reported by: Rainer Koirikivi Owned by: Rainer Koirikivi
Component: contrib.admin Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Accessing the changelist_view of a ModelAdmin subclass results in a NoReverseMatch error if get_urls is overridden so that the "appname_modelname_change" url is removed, but "appname_modelname_changelist" is left untouched.

Example ModelAdmin subclass causing this error:

class UnchangeableModelAdmin(admin.ModelAdmin):
    model = models.UnchangeableModel

    def get_urls(self):
        # return the standard urls, except for the change url
        urlpatterns0 = super(UnchangeableModelAdmin, self).get_urls()
        return [p for p in urlpatterns0 if not p.name.endswith("_change")]

Traceback points to line 91 in django/contrib/admin/templates/admin/change_list.html, namely the result_list template tag.

Related issue: #20640

Change History (5)

comment:1 by Rainer Koirikivi, 11 years ago

Created a test project to verify this bug and #20640: https://github.com/koirikivi/django-admin-views-test

comment:2 by Tim Graham, 11 years ago

Component: Uncategorizedcontrib.admin
Triage Stage: UnreviewedAccepted

comment:3 by Rainer Koirikivi, 11 years ago

Owner: changed from nobody to Rainer Koirikivi
Status: newassigned

comment:4 by Rainer Koirikivi, 11 years ago

Has patch: set

Topic branch at https://github.com/koirikivi/django/tree/ticket_20934
Pull request at https://github.com/django/django/pull/1499

Tests pass under sqlite and postgresql

comment:5 by Tim Graham <timograham@…>, 11 years ago

Resolution: fixed
Status: assignedclosed

In 65cf82bd08631a7aa8d9dd007b2527476fa3304f:

Fixed #20934 -- Avoided NoReverseMatch in ModelAdmin.changelist_view

The view tried to display links to a ModelAdmin's change_view, which
resulted in NoReverseMatches if get_urls was overridden to remove the
corresponding url.

Note: See TracTickets for help on using tickets.
Back to Top