#33894: Bug: Underscore in CharField as Primary Key breaks related link
displayed
by admin's ForeignRawIdWidget
-------------------------------------+-------------------------------------
Reporter: Robert- | Owner: nobody
Lebedeu |
Type: Bug | Status: new
Component: | Version: 3.2
contrib.admin | Keywords: Underscore,
Severity: Normal | CharField, Primary Key, link,
Triage Stage: | reverse
Unreviewed | Has patch: 1
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
I understand that in order to handle primary keys that may contain special
characters, the usage of {{{django.contrib.admin.utils.quote}}} is
needed.
I see that the method {{{label_and_url_for_value(...)}}} of
{{{ForeignKeyRawIdWidget}}} doesn't escape the primary key when
calculating the related object URL.
I suppose the solution to this problem would be adding
{{{args=quote(obj.pk),}}} to the {{{reverse}}} call.
Small example to re-create the BUG:
1. Create following models:
{{{
from django.db import models
class ModelA(models.Model):
id = models.CharField(max_length=100, primary_key=True)
class ModelB(models.Model):
a_model = models.ForeignKey(ModelA)
}}}
2. Enable and register both models to the admin
3. Add {{{a_model}}} field to {{{raw_id_fields}}} of ModelBAdmin
4. Create one instance per model
5. Try using related link displayed by {{{ForeignKeyRawIdWidget}}} and see
how it doesn't work.
--
Ticket URL: <https://code.djangoproject.com/ticket/33894>
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/0107018269311113-6cd6adcb-e0ce-4570-bad6-152c76e143eb-000000%40eu-central-1.amazonses.com.