Code

#20934 closed Bug (fixed)

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

Reported by: koirikivi Owned by: koirikivi
Component: contrib.admin Version: master
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

Attachments (0)

Change History (5)

comment:1 Changed 11 months ago by koirikivi

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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

comment:2 Changed 11 months ago by timo

  • Component changed from Uncategorized to contrib.admin
  • Triage Stage changed from Unreviewed to Accepted

comment:3 Changed 11 months ago by koirikivi

  • Owner changed from nobody to koirikivi
  • Status changed from new to assigned

comment:4 Changed 11 months ago by koirikivi

  • 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 Changed 11 months ago by Tim Graham <timograham@…>

  • Resolution set to fixed
  • Status changed from assigned to closed

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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.