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.
* version: 3.2 => dev
--
Ticket URL: <https://code.djangoproject.com/ticket/33894#comment:1>