访问父变量

时间:2014-10-22 10:40:31

标签: django inheritance django-class-based-views

我有两个继承自Base类的基于类的视图:

class Base(object):
    context_object_name = "book_list"
    model = Book
    def get_context_data(self, **kwargs):
        context = super(Book, self).get_context_data(**kwargs)
        return context
    def get_queryset(self):
       book_set = Book.objects.all()
       return book_set

class C1(Base ,ListView):
    paginate_by = 20 
    template_name = 'sl/v1.html'

class C2(Base, View):
    template_name = 'sl/v2.html'

我需要对C2类中的queryset结果进行一些处理。那么如何才能访问C2中的book_list?

1 个答案:

答案 0 :(得分:0)

class C2(Base, View):
    template_name = 'sl/v2.html'

    def get_queryset(self):
        qs = super(C2, self).get_queryset()
        # do something

        return qs