Django jQuery Tags Input 是一个 Django 字段和部件包装器,它为 `ManyToManyField` 和 `ForeignKey` 字段提供了易于使用的界面,带有自动完成标签,并可可选地实时创建新关联项。
项目描述
概述
Django Tags Input 是一个模块,它提供了 Django 中 Xoxco jQuery Tags Input 库的修改版本。
结果是带有标签和自动完成的非常漂亮的界面,当缺少项目时,可可选地自动创建新项目。
Django Tags Input 最有用的功能之一是它按照您输入的顺序存储元素。
所以如果您将 B, A, C 插入到数据库中,它将按照您输入的顺序返回:B, A, C。
链接
如何安装
安装此模块只需几分钟。
目前支持并测试了 Django 2.2、3.1 和 3.2 与 Python 3.7、3.8、3.9 和 3.10 的组合。
对于低于 Django 2.2 的 Django 和 Python 2.7,版本 4.6.0 应该可以工作。
对于 Django 1.4、Django 1.5、Django 1.6 和 Django 1.7,与 Python 2.6 和 2.7 的组合,可以使用 Python 3.2、3.3 和 3.4。Pypy 和 Pypy3 版本 2.1.0 可用。
安装模块本身
pip安装django-tags-input
或者
easy_install django-tags-input
将 tags_input 添加到 Django 的 settings.py 配置中的 INSTALLED_APPS 设置。
示例
INSTALLED_APPS = ( # ... your other installed apps 'tags_input', )
将映射添加到您的 settings.py 文件中
示例
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_input URL 添加到您的 urls.py
示例
from django.conf import urls urlpatterns = patterns('', url(r'^tags_input/', include('tags_input.urls', namespace='tags_input')), # ... other urls ... )
管理员使用
from django.contrib import admin
import models
from tags_input import admin as tags_input_admin
class YourAdmin(tags_input_admin.TagsInputAdmin):
#Optionally specify which ManyToMany fields are to be used for tagging
#Or define a get_tag_fields() method
tag_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 Django 3.0
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 登录。
之后,您可以通过以下链接尝试添加一些额外的 Foo 对象: http://localhost:8000/admin/autocompletionexample/spam/2/
请注意,示例中的一些部分故意破坏,以测试在损坏的环境中的行为。
项目详情
下载文件
下载适用于您平台的应用程序文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。