为django项目选择2小部件“light edition”

django-select2light的Python项目详细描述


Django-select2灯[构建状态](https://travis-ci.org/ouhouhsami/django-select2light.png?branch=master)(https://travis ci.org/ouhouhsami/django-select2light)

REW](https://github.com/applegrew)




安装
==

1。安装django_select2light

pip安装django_select2light

2。将"select2light"添加到项目设置中的"installed_apps"(还必须添加"floppyforms"和"tastype")


3。在生产服务器上部署时,请运行





*外部依赖项
====

*django,只要这是django应用程序……
*django floppyforms,用于创建select2 html模板
*django tastype,used来构建ajax请求

注意:
*此应用程序提供了一个jquery副本和select2版本3.3.2的"个人丑陋黑客"(请参见select2light/static/select2-3.3.2/select2.js initselection:对于单个和多个字段)
*对于此包,我使用了[django tastype](http://django tastype.readthedocs.org/en/latest/),但我们可以很容易地使用[django rest framework](http://django rest framework.org/),以及[django活塞](https://django piston.readthedocs.org/en/latest/documentation.html))



---------------------------

这只是一个小部件定制。使用select2widget或select2multiplewidget,您将用modelschoicefield的select2widget或modelsmultiplewidget替换默认widget。

选择2 ModelChoiceField,从Select2Light.Widgets导入Select2Widget中选择2 ModelMultipleChoiceField
从Select2Light.Widgets导入Select2Widget,选择2 MultipleWidget
表单模型导入栏,baz

直接使用自定义字段
类fooform(forms.form):
栏=Select2ModelChoiceField(queryset=bar.objects.all())
bazs=select2模型多选项字段(queryset=baz.objects.all())

或者只使用widget
类fooform(forms.form):
bar=forms.modelchoicefield(queryset=bar.objects.all(),widget=select2widget)
bazs=forms.modelmultiplechoicefield(queryset=baz.objects.all(),widget=select2multiplewidget)


他在[forms.py]中的"employeeform"modelform类meta(https://github.com/ouhouhsami/django-select2light/blob/master/testapp/testapp/testmain/forms.py/l13)


注意:
*如果只使用select2widget(而不是下面描述的ajax widget),则不需要安装tastype或floppyforms.
*如果要设置select2实例的特定参数(请参见本页构造函数部分的列表http://ivaynberg.github.io/select2/),则在这种情况下,需要重写默认的select2light/select2.html模板。根据用户的需要,我们可以考虑,如下所示,对于ajax小部件,使用一些实例化参数来配置select2小部件。



--------


\django tastype part

为您希望与select2一起用作小部件的资源(大多数情况下是django模型)创建一个modelresource。为此,您必须阅读[django tastype]文档(http://django-tastype.readthedocs.org/en/latest/)。以下是概要:


在应用程序内的"api.py"文件中为django模型创建一个modelresource(请参见[api.py](https://github.com/ouhouhsami/django-select2light/blob/master/testapp/testapp/testmain/api.py))

r/>筛选={
"名称":假设bar有一个名为name
}





urls.py文件
从django.conf.urls导入*
从tastype.api导入api
从myapp.api导入barresource

foo_api=api(api_name='foobar')
foo_api.register(barresource())

您的urlpatterns

urlpatterns+=模式('',
(r'^api/',include(foo-api.url)),





在"ajaxselect2widget"(或"ajaxselect2multiplewidget")中,您可以配置以下参数:
*"resource_name"(必需)是您的tastype modelresource中设置的值(请参阅示例[api.py](https://github.com/ouhouhsami/django-select2light/blob/master/testapp/testapp/testmain/api.py#L14))
*`API_name`(必需)是在url.py中设置的API值(请参见示例[urls.py](https://github.com/ouhousami/django-select2light/blob/master/testapp/testapp/urls.py l6))
*`Label_key`(可选)对应于要在模型资源中搜索的字段。默认设置为"name"。有两种方法可以使用它:将字段名"name"添加到模型资源中(和[使用dehydrate tastype功能](http://django tastype.readthedocs.org/en/latest/cookbook.html"添加自定义值"),或者将"label""key"设置为模型资源上的自定义字段,以便按这个键。

```
forms.py文件
从模型导入栏
将floppyforms导入为forms
form select2light.models导入ajaxselect2modelchoicefield,ajaxselect2modelmultiplechoicefield
form select2light.wigets导入ajaxselect2widget,ajaxselect2multiplewidget

直接自定义字段
类fooform(form.form):
假设bar model有一个名称字段
bar=ajaxselect2modelchoicefield(queryset=bar.objects.all(),
resource_name='bar',api_name='foobar')
bazs=ajaxselect2modelmultiplechoicefield(queryset=baz.objects.all(),
资源名为bar,api名为foobar')

或者只使用widget
类fooform(form.form):
假设bar model有一个name字段
bar=forms.modelchoicefield(queryset=bar.objects.all(),
widget=ajaxselect2widget(resource_name='bar',api_name='foobar')
bazs=forms.modelmultiplechoicefield(queryset=baz.objects.all(),
widget=ajaxselect2多功能widget(resource_name='baz',api_name='foobar')
````

注意:
对于modelform,您只需覆盖modelform的类meta中的widget dict,就像在测试应用程序[forms.py]中所做的那样(https://github.com/ouhousami/django-select2light/blob/master/testapp/testapp/testmain/forms.py l15)。



管理集成
====


您可以使用管理中的小部件或字段。testapp项目提出了不同的用例,请参见[admin.py](https://github.com/ouhouhsami/django-select2light/blob/master/testapp/testapp/testmain/admin.py)获取示例。




要进一步(共享思想)
===tom html5 datalist实现
*与rest框架无关,尝试使用上面提到的任何django rest框架
*删除"hold down"co"control"或"command"在Mac上选择多个。"on select multiple widget rendering."在"select multiple widget rendering"上。





==

<0.3
*将Travis CI添加为连续集成服务
*添加管理集成示例

<0.2
*添加测试
*添加字段选择2 modelchoicefield,选择2 model multiplechoicefield,ajaxselect2modelchoicefield,ajaxselect2modelmultiplechoicefield为了方便起见,请使用[applegrouw]提出的基本结构(https://github.com/applegrouw)




示例应用程序,更新自述文件

<0.1
*测试可行性。
此应用程序用于手动测试此软件包的功能。这也是一个很好的起点示例。

您可以使用github存储库测试django-select2light(还应该考虑使用virtualenv和virtualenvwrapper)


mkvirtualenv django-select2light-test
git clone https://github.com/ouhousami/django-select2light.git
cd django-select2light
pip install-requirements.txt
pip install-r requirements tests.txt
add2virtualenv select2light
cd testapp
python manage.py syncdb
python manage.python runserver

,然后转到http://127.0.0.1:8000/!



您还可以使用pypi上提供的tar.gz存档测试此应用程序。


下载tar.gz https://pypi.python.org/pypi/django-select2light/
解压缩它
运行"python setup.py install"
将converage和django coverage安装到testapp
python manage.py syncdb
python manage.py runserver
转到http://127.0.0.1:8000/



license
=



Copyright 2012 Samuel Goldszmidt


根据Apache许可证2.0版("许可证")获得许可证;
除非符合许可证,否则您不得使用此项目。
您可以在

[http://www.apache.org/licenses/license]获取许可证副本。-2.0)(http://www.apache.org/licenses/license-2.0)

许可下的限制。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java正则表达式查找但不包含在组中   java在for循环内的主线程中调用AsyncTask   java解析SOAP服务的响应时遇到问题。XML有什么问题?   java Servlet ClassNotFoundException出现在包中时。。。为什么?   Facebook SDK中的安卓 R.Java与应用程序R.Java冲突   java为什么我得到SSLProtocolexception:尝试发送http请求时握手失败?   java Base64编码字符串搜索   在htmlunit中选择java下拉菜单   java列表添加到HashMap   java设置断点的最短NOOP语句是什么?   java如何检索windows中所有应用程序最近使用的文件   java正则表达式,包含正向向后看和向前看   如何在java中通过API从url获取图像?   如何将for-each循环转换为Java流和lambda函数?   java如何使用jackson流式api解析给定的json?   java暂停调用方法jdbcTemplate。getDataSource()   java如何在使用getJdbcTemplate时使用union运算符设置sql查询的参数。查询(sql、新对象[]、行映射器)?   java我可以为HQL查询指定结果对象类型吗?   java Spring未满足的依赖项错误   maven试图重新定位poi jar,但未找到java类异常