[Answered ]-Combining MultipleObjectMixin and FormView

2👍

You are going to run into problems with this approach.

Python uses a method resolution order to determine which method on the parent class(es) gets called. In your case, super(UnseenActivityView, self).get_context_data() will call MultipleObjectMixin.get_context_data but not FormView.get_context_data. Either way you will not end up with the context from both parent classes being passed to your template, and something will break.

This is also the reason you are getting the KeyErrorMultipleObjectMixin.get_context_data expects an object_list kwarg, but isn’t supplied one, because the get() method that normally calls get_context_data() is coming from the FormView (method resolution again), which has no knowledge of any object_list.

I would suggest that rather to combine these classes in this way you heed the advice in the documentation:

Generic views will have a limit. If you find you’re struggling to implement your view as a subclass of a generic view, then you may find it more effective to write just the code you need, using your own class-based or functional views.

In this case I’d suggest you use the FormView to handle your form, but write the code for handling a list view yourself rather than trying to plug in the MultipleObjectMixin. You can of course copy the logic from MultipleObjectMixin.

Leave a comment