django jquery tags input是一个django字段和小部件包装器,它为“manytomanyfield”和“foreignkey”字段添加了一个易于使用的界面,以自动完成标记的形式,并可以选择实时创建新的链接项。
django-tags-input的Python项目详细描述
概述
django标记输入是一个模块,它为您提供django中xoxco jquery标记输入库的修改版本。
结果是一个非常漂亮的界面与标签和自动完成,可以选择自动创建新的项目时,他们失踪。
django标记输入最有用的特性之一是,它按照输入的顺序存储元素。
因此,如果您将b,a,c插入数据库,它将按您输入的方式返回它:b,a,c。
链接
- The source: https://github.com/WoLpH/django-tags-input
- Project page: https://pypi.python.org/pypi/django-tags-input
- Reporting bugs: https://github.com/WoLpH/django-tags-input/issues
- Documentation: http://django-tags-input.readthedocs.org/en/latest/
- My blog: http://w.wol.ph/
如何安装
安装这个模块只需要几分钟。
目前Django1.8、1.9、1.10和1.11与Python2.7、3.2、3.3、3.4、3.5、3.6和PyPy一起支持和测试。
对于django 1.4、django 1.5、django 1.6和django 1.7以及 Python2.6和2.7。python 3.2、3.3和3.4。pypy和pypy3版本2.1.0可以 被利用。
安装模块本身
pip install django-tags-input
# or
easy_install django-tags-input
将tags_input添加到djangosettings.py中的INSTALLED_APPS设置中。
Example:
INSTALLED_APPS=(# ... your other installed apps'tags_input',)
将映射添加到settings.py文件:
Example:
TAGS_INPUT_MAPPINGS={'some_app.SomeKeyword':{'field':'some_field',},'some_app.SomeOtherKeyword':{'fields':('some_field','some_other_field'),},'some_app.SomeSortedKeyword':{'field':'some_field','ordering':['some_field','some_other_field',],'filters':{'some_field__istartswith':'a',},'excludes':{'some_field__iexact':'foobar',},},'some_app.SomeCreateableKeyword':{'field':'some_field','create_missing':True,},}
将tags_inputurl添加到urls.py:
Example:
fromdjango.confimporturlsurlpatterns=patterns('',url(r'^tags_input/',include('tags_input.urls',namespace='tags_input')),# ... other urls ...)
管理用法
fromdjango.contribimportadminimportmodelsfromtags_inputimportadminastags_input_adminclassYourAdmin(tags_input_admin.TagsInputAdmin):#Optionally specify which ManyToMany fields are to be used for tagging#Or define a get_tag_fields() methodtag_fields=["some_field"]admin.site.register(models.YourModel,YourAdmin)
快速启动
要测试项目,只需克隆存储库,请安装并运行示例:
# mkvirtualenv is part of virtualenvwrapper, using a regular virtualenv, pyvenv or pipenv is also possible # Or even without any type of virtualenv at all mkvirtualenv django-tags-input git clone https://github.com/WoLpH/django-tags-input.git # Tested with up to Django 2.1 pip install django pip install -e 'django-tags-input[tests]'cd django-tags-input/example python manage.py runserver
现在您可以转到http://localhost:8000/admin/并使用用户名和 密码admin和admin分别。
在此之后,您可以尝试通过spamadmin添加一些额外的foo对象 这里:http://localhost:8000/admin/autocompletionexample/spam/2/
注意,为了测试 在破碎环境中的行为。