Opened 18 years ago

Closed 18 years ago

Last modified 17 years ago

#2023 closed (fixed)

"View on site" breaks when model specifies primary key other than ID

Reported by: emeraldjunk-django@… 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 Adrian Holovaty, 18 years ago

Resolution: fixed
Status: newclosed

(In [3009]) Fixed #2023 -- 'View on site' now works with non-integer primary keys.

comment:2 by Go, 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 Gary Wilson, 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.
Back to Top