Code

Opened 3 years ago

Closed 3 years ago

#15508 closed (fixed)

DetailView view looks for pk or slug by default but the error says id or slug.

Reported by: varikin Owned by: nobody
Component: Generic views Version: 1.3-alpha
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description (last modified by russellm)

With the following url rule

    url(r'^order/(?P<id>\d+)/$', DetailView.as_view(model=Order), name='order-detail')

Django throws the following error:

    Generic detail view order must be called with either an object id or a slug.

From django/django/views/generic/detail.py in get_object, line 45

It confused me for a bit because I am supplying the id of the object. Upon looking at detail.py, it looks for pk and slug. I checked the documentation and found that does mention pk and slug as well, so I am obviously doing it wrong. But, in my mind, id also makes sense. But whether support for id is added or not, I think the error message should be updated to say 'object pk or a slug'.

I am running 1.3 alpha at the moment, but I checked the method trunk it is the same.

Attachments (0)

Change History (2)

comment:1 Changed 3 years ago by russellm

  • Description modified (diff)
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

Good catch -- you're absolutely correct. I'll commit a fix shortly.

comment:2 Changed 3 years ago by russellm

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

In [15652]:

Fixed #15508 -- Corrected a misleading error message in the DetailView generic view. Thanks to varikin for the report.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.