您如何使用django-datatable-view [英] How do you use django-datatable-view

查看:162
本文介绍了您如何使用django-datatable-view的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在构建一个项目,该项目将在Django管理员中显示大量数据,我想使用 django-datatable-view 表示在列表中列出的功能,可以将其替换为列表视图。我可能未正确阅读此书,但从那开始我认为这意味着完全替换列表视图,因此默认情况下使用数据表,这正是我想要的。我是Django的新手,但是似乎没有关于此插件的文档,但是他们有一些示例,但是没有关于如何实际使用他们声称存在的功能的文档,有人使用此插件将Django中的列表视图替换为数据表。默认情况下,我想尝试对所有创建的新模型进行此操作,但对于尚未创建的auth等模型,也要进行默认设置。

解决方案

好吧,我已经在本地主机上测试了该应用程序,这是一些结果(太多评论,所以我将在这里回答)



首先,您需要在这里看看: http://django-datatable-view.appspot.com/



它有一些有关如何实现django-datatable-view的文档。例如:
http://django-datatable-view.appspot.com / zero-configuration / 获得了如何编写视图以基于模型实现表的方法,



http://django-datatable-view.appspot.com/ordering/ 了解了如何在表格中获取订单



http:// django-datatable- view.appspot.com/javascript-initialization/ 已获得有关 js 的信息。



最好克隆存储库并在localhost中运行。在那里,您将能够尝试视图和模板(就像我尝试做/做的那样)。



在这里: https://github.com/pivotal-energy -solutions / django-datatable-view / blob / master / datatableview / tests / example_project / example_project / example_app / views.py ,您将看到多种视图类型(无配置表,特定列表等)已被编码。



第二,到目前为止,我尝试过什么:
我的项目结构如下:

 -项目
manage.py
-myapp(文件夹)
views.py
models.py
urls.py
-datatableview *(文件夹)
-projectapp(文件夹)
settings.py
urls.py

**从克隆的仓库中,我复制了datatableview文件夹并将其粘贴到我的项目中。



在myapp>模型中:

  class Post(models.Model):
title = models.CharField(max_length = 150)
body = models.TextField()
创建= models.DateField()

在myapp>视图中:

  class MyView(DatatableView):
模型=发布
datatable_options = {
'columns ':[[
'title',
'body',
'created',
]
}

在myapp>网址中:

  url(r'^ $',MyView.as_view(),name ='myview'), 

在模板中:
in(tempaltes / myapp / post_list.html)

  {%块内容%} 
{{datatable}}
{{object_list}}
{% endblock%}

结果是这样的:

 标题正文已创建
[< post:一个> ;,< post:两个>]

此处创建的标题正文是表的列标题的名称。



< PS:我知道这没有多大帮助,但是希望这些信息可以帮助您进一步发展。还有一点建议,请看看 django-tables2


I am currently building a project that will be displaying quite a bit of data in the Django admin I would like to substitute the list view used for datatables using django-datatable-view it says in the list for features that it can be dropped in as a replacement for list view. I might be not reading this correctly but from that I think it means totally replace list view so data tables are used by default which is what I want. I am new to Django and there seems to be no documentation on this add-on they have a few samples but no docs on how to actually use features they claim exist has anyone replaced the list view in Django with datatables using this add-on. I want to try and do it by default for all new models created but also the models like auth that I haven't extended yet.

解决方案

Well, I have tested this app on my localhost, here is some results(too much for comment, so I will answer here)

First, you need to take a look here: http://django-datatable-view.appspot.com/

It has got some documentation about how to implement django-datatable-view. For example: http://django-datatable-view.appspot.com/zero-configuration/ has got how to write a view to implement a table based on a model,

http://django-datatable-view.appspot.com/ordering/ has got how to get orders in table,

http://django-datatable-view.appspot.com/javascript-initialization/ has got information about js.

Better if you clone the repo and run it in localhost. There you will be able to experiment with the views and templates(as I tried to do/did).

In here: https://github.com/pivotal-energy-solutions/django-datatable-view/blob/master/datatableview/tests/example_project/example_project/example_app/views.py, you will see how multiple types of view(For no configuration table, specific column table etc) has been coded.

Second, what have I tried so far: My structure for this project was like this:

-Project
 manage.py
   -myapp(folder)
      views.py
      models.py
      urls.py
   -datatableview*(folder)
   -projectapp(folder)
      settings.py
      urls.py

*From cloned repo, I copied datatableview folder and pasted it in my project.

In myapp>models:

class Post(models.Model):
       title= models.CharField(max_length=150)
       body = models.TextField()
       created = models.DateField() 

In myapp>views:

class MyView(DatatableView):
    model = Post
    datatable_options = {
        'columns': [
            'title',
            'body',
            'created',
            ]
    }

In myapp>urls:

url(r'^$', MyView.as_view(),  name='myview'),

In templates: in (tempaltes/myapp/post_list.html)

{% block content %}
{{ datatable }}
{{ object_list }} 
{% endblock %}

Result was like this:

title   body    created
[<post: one >, <post: two>]

here title body created are names of table's column header.

PS: I know its not much of a help, but hopefully this information will help you go further. And a little recommendation, please take a look at django-tables2

这篇关于您如何使用django-datatable-view的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆