Opened 12 years ago

Closed 12 years ago

#20234 closed Bug (fixed)

SingleObjectMixin does not add 'object' key to context

Reported by: Matthew Somerville Owned by: Karol Sikora
Component: Generic views Version: dev
Severity: Normal Keywords:
Cc: tinodb, marc.tamlyn@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The documentation at https://docs.djangoproject.com/en/dev/ref/class-based-views/mixins-single-object/#django.views.generic.detail.SingleObjectMixin says that 'object' will be in the context, as well as potentially context_object_name if given. However, actually only context_object_name is set in the context by this mixin; only if object is passed to the mixin (which BaseDetailView does) will it be included.

The MultipleObjectMixin does include 'object_list' in its get_context_data (though assumes it must be passed in rather than on the object, I'll file that as another ticket), so I assume this is an issue with SingleObjectMixin, and that it should set 'object' on context whether it is passed in as a kwarg or not.

I have a patch on a branch of my github fork: https://github.com/dracos/django/compare/singleobjectfixin

Change History (6)

comment:1 by Matthew Somerville, 12 years ago

Component: UncategorizedGeneric views

If this ticket is applied, then I think get_context_data of ModelFormMixin becomes entirely superfluous - see ticket #20236.

comment:2 by tinodb, 12 years ago

Cc: tinodb added
Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

Hmm, all "object" stuff does not seem to be very consistent (like you mention in your other tickets).

It also strikes me as strange, that these mixins rely on self.object being set, while it is only set in it's derived classes (that is probably why object was passed as a kwarg earlier).

comment:3 by Marc Tamlyn, 12 years ago

Cc: marc.tamlyn@… added

I think the documented functionality is the correct functionality and this and #20236 can be fairly easily tidied up together.

comment:4 by Markus Holtermann, 12 years ago

Owner: changed from nobody to Markus Holtermann
Status: newassigned

comment:5 by Karol Sikora, 12 years ago

Owner: changed from Markus Holtermann to Karol Sikora

I'will resolve this ticket together with #20236.

comment:6 by Karol Sikora <elektrrrus@…>, 12 years ago

Resolution: fixed
Status: assignedclosed

In 3eba8c7f7fc4877e7df0f83fe3bacd88082ac33e:

Fixed #20234 and #20236 -- SingleObjectMixin fixes

Added object on SingleObjectMixin returned context,
some code clanup.

Note: See TracTickets for help on using tickets.
Back to Top