用于内容分类的django可重用应用程序。
django-sitecats的Python项目详细描述
https://github.com/idlesign/django-sitecats
说明
django可重用的内容分类应用程序。
不,-你说,-所有的标签业务都缺乏结构化。
这个应用程序只是关于构建数据结构:构建类别层次结构并将站点实体链接到这些类别。
# Somewhere in views.pyfromdjango.shortcutsimportrender,get_object_or_404# Suppose Article model has sitecats.models.ModelWithCategory class mixed in.from.modelsimportArticledefarticle_details(self,request,article_id):"""See, there is nothing special in this view, yet it'll render a page with categories for the article."""returnself.render(request,'article.html',{'article':get_object_or_404(Article,pk=article_id)})defarticle_edit(self,request,article_id):"""Let's allow this view to render and handle categories editor."""article=get_object_or_404(Article,pk=article_id)# Now we enable category editor for an article, and allow users# to add subcategories to `language`, and `os` categories# (suppose we created them beforehand with Admin contrib),# and link this article to them.article.enable_category_lists_editor(request,editor_init_kwargs={'allow_new':True},additional_parents_aliases=['language','os'])form=...# Your usual Article edit handling code will be here.returnrender(request,'article.html',{'article':article,'form':form})
模板编码基本上可以归结为sitecats_categories模板标记用法:
<!-- The same html is just fine for demonstration purposes for both our views. Do not forget to load `sitecats` template tags library. --> {% extends "base.html" %} {% load sitecats %} {% block contents %} <!-- Some additional functionality (e.g. categories cloud rendering, editor enhancements) will require JS. --><scriptsrc="{{ STATIC_URL }}js/sitecats/sitecats.min.js"></script><h1>{{ article.title }}</h1><divid="article_categories"> {% sitecats_categories from article %} <!-- And that's it. --></div><!-- Form code goes somewhere here. --> {% endblock %}
阅读文档,sitecats可以做更多。