易于使用的django表api
sheepdog-tables的Python项目详细描述
这个api有助于快速而简单地创建表。它允许 显示模型数据、任意数据、注释数据等。 它还允许通过CSV导出视图进行简单的CSV导出。
代码库有很好的文档记录,每个类都应该有一个相关的 文档字符串。
安装
使用pip安装python包
$ pip install sheepdog-tables
安装javascript依赖项
具有支持的javascript依赖项版本的bower配置示例。
{"name":"my_project","version":"0.0.0","dependencies":{"bootstrap":"3.0.1","backbone":"1.0.0","underscore":"1.4.4"}}
js是用coffeescript编写的,我们建议使用如下项目 django压缩器来压缩静态文件并在 代表你。
$ pip install django-compressor==1.3
<scripttype="text/javascript"src="{% static "bower/jquery/jquery.min.js"%}"></script><scripttype="text/javascript"src="{% static "tables/js/jquery.ba-bbq.js"%}"></script><!-- To enable filtering --><scripttype="text/javascript"src="{% static "bower/underscore/underscore.js"%}"></script><scripttype="text/javascript"src="{% static "bower/backbone/backbone.js"%}"></script><scripttype="text/coffeescript"src="{% static "tables/js/filtering.coffee"%}"></script><!-- Event binding for sorting, pagination, etc. --><scripttype="text/coffeescript"src="{% static "tables/js/binding.coffee"%}"></script>
起点
这个api应该注意一些事情。添加的主要混合内容 表到页是TablesMixin。找到对应的模板 在tables/tables.html中。MIXIN应该混合到一个类中。 视图从ListView继承。是get_context_data方法 应该在ListView的相同函数之后运行。
每个表都要声明为类参数。例如,如果我有 两个表Table1和Table2,我们可以有一个看起来 像这样:
classMyView(TablesMixin,ListView):table_1=Table1()table_2=Table2()defget_context_data(self,**kwargs):context=ListView.get_context_data(self,**kwargs)context.update(TablesMixin.get_context_data(self,**kwargs)
table类的工作方式与模型类似。完整的文档 这是类doc string。
此API的良好实践
django和python的一般规则适用于 应用程序编程接口。一般来说,把你所有的桌子都放在 tables.py文件中的应用程序,以及各自独立的列 columns.py文件,就像表单和字段一样。