2013-11-24 28 views
0

我正在迁移我们的旧应用程序到Django 1.6。django迁移到1.6的旧应用程序:ListView

现在,一些观点已经被编程这样:

from django.views.generic.list_detail import object_list 

@render_to("items/index.html") 
def index(request): 
    profile = request.user.get_profile()  
    args = clean_url_encode(request.GET.copy().urlencode()) 
    context = { 
     'is_dashboard': True, 
     'body_id': 'dashboard', 
     'object_list': None, 
     'args':args, 
     'show_in_process':False 
    } 
    return context 

我知道,我现在需要使用新的ListView,但实例和文档似乎不告诉我,我有这种特殊情况下:在上下文中传递object_list。

我该如何调整此代码以使用基于类的新通用视图?我是否也可以只使用ListView.asView()而不是'object_list':None ?

回答

0

如果您没有对象列表,为什么使用ListView?我认为TemplateView应该完成这项工作。你只需要重写get_context_data,并提供自定义上下文

class IndexView(TemplateView): 
    template_name = 'items/index.html' 

    def get_context_data(self, **kwargs): 
     context = super(IndexView, self).get_context_data(**kwargs) 
     profile = self.request.user.get_profile() 
     args = clean_url_encode(self.request.GET.copy().urlencode()) 
     context.update({ 
      'is_dashboard': True, 
      'body_id': 'dashboard', 
      'object_list': None, 
      'args':args, 
      'show_in_process':False 
     }) 
     return context 
+0

感谢@tuxcanfly,所以如果我没有理解好,每一个这样的功能变成了自己的视图类?这将是相当多的迁移我们... – faboolous

+0

我明白了。不是所有的功能,只是通用的看法。 – faboolous

相关问题