In the simplified example below, how do I reference the context variable "Elephant" (created in the class Lion) from inside the class Leopard?
I have researched and tried a number of ways, including the last line below which results in a KeyError for "Elephant".
views.py
class Lion(ListView):
def get_context_data(self, **kwargs):
context super().get_context_data()
context[“Elephant”] = Rhinoceros
context["Giraffe"] = Eagle
return context
class Leopard(ListView):
Buffalo = Lion.get_context_data(context[“Elephant”])
One option is to create your own
ListViewsuper class:Now your other list views can inherit this instead of inheriting form
ListViewdirectly:Alternatively, you can make the class a mixin:
And then your list views should inherit from both
ListViewand this mixin: