Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add data to context object in DetailView?

I need to write a DetailView in Django. I achieved this functionality. However, I need to add some more data along with the context object. How will I achieve this.

My generic view is:

class AppDetailsView(generic.DetailView):
    model = Application
    template_name = 'appstore/pages/app.html'
    context_object_name = 'app'

I need to add one more variable to the context object:

response = list_categories(storeId)
like image 364
deltaforce Avatar asked Oct 23 '25 10:10

deltaforce


1 Answers

How about using get_context_data

class AppDetailsView(generic.DetailView):
     model = Application
     def get_context_data(self, **kwargs):
        context = super(AppDetailsView, self).get_context_data(**kwargs)
        context['categories'] = list_categories(storeId)
        return context
like image 166
burning Avatar answered Oct 26 '25 21:10

burning