I constantly see myself having to add the same extra variable to the context of many of my views.
def get_context_data(self, **kwargs):
# Call the base implementation first to get a context
context = super(MyListView, self).get_context_data(**kwargs)
# Add in the house
context['house'] = self.get_object().house
return context
As I don't like repeating myself, I thought I could create a new class extending the view and then I could base all my views on the new extended view class. The thing is, there are 4 classes of views I use: CreateView, UpdateView, ListView and DeleteView. Do I really have to create a new class for each of one of them?
Isn't there something like a django "base" view class? Maybe a smarter way to do this? Many thanks in advance!