MultipleObjectMixin requires object_list to be passed in rather than using self.object_list
|Reported by:||Matthew Somerville||Owned by:||Markus Holtermann|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||yes|
Unlike SingleObjectMixin, which uses self.object in its get_context_data, MultipleObjectMixin requires that object_list is passed in to get_context_data as a kwarg. BaseListView does this, but using MultipleObjectMixin separately requires this knowledge, not documented on the mixin page at https://docs.djangoproject.com/en/dev/ref/class-based-views/mixins-multiple-object/#django.views.generic.list.MultipleObjectMixin . It is alluded to at https://docs.djangoproject.com/en/dev/ref/class-based-views/generic-display/#django.views.generic.list.BaseListView but I don't think this is clear, and I think having it in MultipleObjectMixin is a better location, as with SingleObjectMixin.
As I assume MultipleObjectMixin is in use already with its current behaviour, I believe the nicest fix is to add a default to the pop() so that MultipleObjectMixin can be used by setting self.object_list in your subclass, the same as with SingleObjectMixin and self.object.
I have a patch on a branch of my github fork: https://github.com/dracos/django/compare/multipleobjectfixin
Change History (8)
comment:2 Changed 4 years ago by
|Component:||Uncategorized → Generic views|
|Type:||Uncategorized → Cleanup/optimization|
comment:4 Changed 4 years ago by
|Owner:||changed from nobody to Markus Holtermann|
|Status:||new → assigned|