django taggit标记的django管理助手类
django-taggit-helpers的Python项目详细描述
django-taggit-helpers使使用与django-taggit标记关联的模型的管理页更容易。
github上的源代码位于mfcovington/django-taggit-helpers。有关django-taggit的信息可在GitHub和Read the Docs上找到。
django-taggit-helpers与python 2.7+/3.2+和django 1.7+兼容。
Installation
pypi
pip install django-taggit-helpers
github(开发分支)
pip install git+http://github.com/mfcovington/django-taggit-helpers.git@develop
Configuration
在settings.py:
中将taggit_helpers添加到INSTALLED_APPS中INSTALLED_APPS=(...'taggit','taggit_helpers',)
Helper Classes
^{tt5}$
显示(和排序)与标记项关联的taggit标记数。
fromtaggit_helpersimportTaggitCounter# For Django 1.9+, use this instead:# from taggit_helpers.admin import TaggitCounterclassMyModelAdmin(TaggitCounter,admin.ModelAdmin):# TaggitCounter before ModelAdminlist_display=(...'taggit_counter',)
注意:当前,TaggableManager()字段必须命名为tags。
注意:若要避免过度计数,请设置distinct=True,如果要用Count():
queryset.annotate(m2m_field_count=Count('m2m_field',distinct=True))
^{tt6}$
仅按当前模型的taggit标记筛选记录。 标签按名称的字母顺序排列。
fromtaggit_helpersimportTaggitListFilter# For Django 1.9+, use this instead:# from taggit_helpers.admin import TaggitListFilterclassMyModelAdmin(admin.ModelAdmin):list_filter=[TaggitListFilter]
^{tt7}$
将taggit标记的堆叠内联添加到管理。 标签按名称的字母顺序排列。
fromtaggit_helpersimportTaggitStackedInline# For Django 1.9+, use this instead:# from taggit_helpers.admin import TaggitStackedInlineclassMyModelAdmin(admin.ModelAdmin):inlines=[TaggitStackedInline]
^{tt8}$
将taggit标记的表格内联添加到admin。 标签按名称的字母顺序排列。
fromtaggit_helpersimportTaggitTabularInline# For Django 1.9+, use this instead:# from taggit_helpers.admin import TaggitTabularInlineclassMyModelAdmin(admin.ModelAdmin):inlines=[TaggitTabularInline]
Upgrading existing projects to Django 1.9+
应用程序加载在django 1.9中进行了重构。要使django 1.7/1.8应用程序django 1.9与django-taggit-helpers兼容,请在应用程序目录中运行以下shell命令。
find . -name '*.py'| xargs perl -i -pe 's/from taggit_helpers import/from taggit_helpers.admin import/'
感谢jpic为inspiration为这个片段!
Revision history
0.1.4 2015年12月4日
- 添加django 1.9兼容性
0.1.3 2015年11月30日
- 需要python 2.7+/3.2+
- 添加来自django sf meetup lightning talk的幻灯片
0.1.2 2015年6月14日
- 添加django 1.8兼容性
0.1.1 2015年6月11日
- 将taggit_count重命名为taggit_counter
0.1.0 2015年6月10日
- django taggit标记的django管理助手类
- TaggitCounter
- TaggitListFilter
- TaggitStackedInline
- TaggitTabularInline