#2023 closed (fixed)
"View on site" breaks when model specifies primary key other than ID
Reported by: | Owned by: | Adrian Holovaty | |
---|---|---|---|
Component: | contrib.admin | Version: | dev |
Severity: | normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Model A:
class Photo(models.Model): title = models.CharField(maxlength = 50) slug = models.SlugField('Slug', prepopulate_from = ('title',), help_text='Use auto-suggestion or a simple text string.', ) [...more stuff, ImageField, etc...]
Model B:
class Photo(models.Model): title = models.CharField(maxlength = 50) slug = models.SlugField('Slug', prepopulate_from = ('title',), help_text='Use auto-suggestion or a simple text string.', primary_key='True') [...more stuff, ImageField, etc...]
Model A works fine in the admin (i.e. you can click on "View on site" and you can view the photo), Model B however gives you a 404. Looking at the relevant entry for urls.py from the admin it seems that this expects a numerical primary key and therefor breaks when e.g. the slug becomes primary key.
Note: using the slug as primary key came from copy-and-pasting an example I found on the web, not sure if this frowned upon anyway.
Change History (3)
comment:1 by , 18 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:2 by , 18 years ago
Summary: | "View on site" breaks when model specifies primary key other than ID → "View on site" breaks when model specifies primary key other than ID |
---|---|
Type: | defect |
comment:3 by , 17 years ago
Summary: | "View on site" breaks when model specifies primary key other than ID → "View on site" breaks when model specifies primary key other than ID |
---|
Note:
See TracTickets
for help on using tickets.
(In [3009]) Fixed #2023 -- 'View on site' now works with non-integer primary keys.