#22266: CharField primary keys with underscores are (un)escaped differently in the admin pages ------------------------------------+------------------------------------ Reporter: victor.varvariuc@… | Owner: nott Type: Bug | Status: assigned Component: contrib.admin | Version: 1.6 Severity: Normal | Resolution: Keywords: | Triage Stage: Accepted Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 ------------------------------------+------------------------------------
Comment (by nott): ModelAdmin.get_urls defines the urls like these: {{{ url(r'^$', wrap(self.changelist_view), name='%s_%s_changelist' % info), url(r'^add/$', wrap(self.add_view), name='%s_%s_add' % info), url(r'^(.+)/history/$', wrap(self.history_view), name='%s_%s_history' % info), url(r'^(.+)/delete/$', wrap(self.delete_view), name='%s_%s_delete' % info), url(r'^(.+)/$', wrap(self.change_view), name='%s_%s_change' % info), }}} As long as we do not know the exact primary key regexp, we have to use (.+) Consider we have 2 entries with the following PKs: "test_123" and "test_123/history". There is no way to distinguish change view for "test_123/history" and history view for "test_123". That is why PK quoting was introduced. django.contrib.admin.utils contains 2 functions: quote and unquote. So reversing admin url should usually look like: {{{ reverse('admin:app_model_change', args=(quote(pk),)) }}} Quoting and unquoting doesn't change numerical PKs, that is why this problem haven't been noticed before. By the way, there is a bug with quoting not being applied in add_view, but it can be easily fixed. I suppose we are really lacking the documentation (https://docs.djangoproject.com/en/1.6/ref/contrib/admin/#overriding-vs- replacing-an-admin-template is evertyhing I could find). There is no way to get rid of quoting if we leave (.+) url pattern for PK. So we can leave everything as is. We still can make this pattern configurable, e.g.: {{{ class ModelAdmin(BaseModelAdmin): [...] pk_regexp = ".+" [...] def get_pk_regexp(self): return self.pk_regexp }}} -- Ticket URL: <https://code.djangoproject.com/ticket/22266#comment:5> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/084.91979407f441953dfb7fa0c434208d6a%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.