Opened 9 years ago

Closed 9 years ago

Last modified 8 years ago

#2023 closed (fixed)

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

Reported by: emeraldjunk-django@… Owned by: adrian
Component: contrib.admin Version: master
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

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 Changed 9 years ago by adrian

  • Resolution set to fixed
  • Status changed from new to closed

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

comment:2 Changed 9 years ago by Go

  • Summary changed from "View on site" breaks when model specifies primary key other than ID to "View on site" breaks when model specifies primary key other than ID
  • Type defect deleted

comment:3 Changed 8 years ago by gwilson

  • Summary changed from "View on site" breaks when model specifies primary key other than ID to "View on site" breaks when model specifies primary key other than ID
Note: See TracTickets for help on using tickets.
Back to Top