Generic Detail View context contains object twice.
|Reported by:||Owned by:||nobody|
|Cc:||Triage Stage:||Design decision needed|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
The (simplified and commented) code excerpt below, taken from django/views/generic/detail.py shows that the object is put into context twice, under different keywords. Is this intentional?
The whole construction is most certainly not elegant and makes inheriting from SingleObjectMixin somewhat cumbersome as I have to explicitely set self.object if I don't have BaseDetailView in my class inheritance or override BaseDetailView.get()
class SingleObjectMixin(ContextMixin): def get_context_data(self, **kwargs): # this puts self.object into context under keyword context_object_name context[context_object_name] = self.object context.update(kwargs) return super(SingleObjectMixin, self).get_context_data(**context) class BaseDetailView(SingleObjectMixin, View): def get(self, request, *args, **kwargs): # this puts self.object into context under 'object' --> is this redundancy intentional? self.object = self.get_object() context = self.get_context_data(object=self.object) return self.render_to_response(context)
Change History (3)
comment:1 Changed 4 years ago by
|Patch needs improvement:||unset|
|Triage Stage:||Unreviewed → Accepted|