Opened 11 months ago
Last modified 6 months ago
#35953 assigned New feature
Add composite PK admin support
| Reported by: | Csirmaz Bendegúz | Owned by: | Antoliny |
|---|---|---|---|
| Component: | contrib.admin | Version: | dev |
| Severity: | Normal | Keywords: | |
| Cc: | Csirmaz Bendegúz, Antoliny | Triage Stage: | Accepted |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | yes |
| Easy pickings: | no | UI/UX: | no |
Description (last modified by )
This is a follow up to #373 (CompositePrimaryKey).
My proposal is to separate the primary key fields with a comma e.g. /admin/posts/post/foo,bar/change.
The comma is not escaped when used as a separator, but it is escaped (%2C) when part of the primary key's value.
e.g. pk = ("The,quick", "brown") -> /admin/posts/post/The%2Cquick,brown/change
According to RFC 3986, unesacped commas are allowed in URI paths (as far as I understand).
What if an existing, non-composite primary key contains a comma?
While Django URL encodes commas in the admin URLs (see QUOTE_MAP), it must be able to look up objects by non-encoded PKs too (see #12349, #18550).
The solution is simple. We must check if the model the user is trying access has a composite primary key or not.
Since admin's LogEntry model uses "generic foreign keys", this ticket depends on #35941 (composite GenericForeignKeys).
Change History (6)
comment:1 by , 11 months ago
| Has patch: | set |
|---|---|
| Owner: | set to |
| Patch needs improvement: | set |
| Status: | new → assigned |
| Triage Stage: | Unreviewed → Accepted |
comment:3 by , 10 months ago
| Cc: | added |
|---|
comment:4 by , 8 months ago
| Owner: | removed |
|---|---|
| Status: | assigned → new |
I don't have the time to work on this right now
comment:5 by , 8 months ago
| Owner: | set to |
|---|---|
| Status: | new → assigned |
PR: https://github.com/django/django/pull/18865
Marking as "Needs improvement" due to the dependency on #35941