Opened 3 years ago
Closed 3 years ago
#33894 closed Bug (duplicate)
Underscore in CharField as Primary Key breaks related link displayed by admin's ForeignRawIdWidget
| Reported by: | Robert-Lebedeu | Owned by: | nobody |
|---|---|---|---|
| Component: | contrib.admin | Version: | dev |
| Severity: | Normal | Keywords: | Underscore, CharField, Primary Key, link, reverse |
| Cc: | lorenzo.morandini@… | Triage Stage: | Unreviewed |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
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:
- 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) - Enable and register both models to the admin
- Add
a_modelfield toraw_id_fieldsof ModelBAdmin - Create one instance per model
- Try using related link displayed by
ForeignKeyRawIdWidgetand see how it doesn't work.
Change History (2)
comment:1 by , 3 years ago
| Version: | 3.2 → dev |
|---|
comment:2 by , 3 years ago
| Has patch: | unset |
|---|---|
| Resolution: | → duplicate |
| Status: | new → closed |
| Summary: | Bug: Underscore in CharField as Primary Key breaks related link displayed by admin's ForeignRawIdWidget → Underscore in CharField as Primary Key breaks related link displayed by admin's ForeignRawIdWidget |
Note:
See TracTickets
for help on using tickets.
Duplicate of #30386.