推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
xi2008wang
V2EX  ›  Python

django 里文章目录简介 id 怎么方便操作

  •  
  •   xi2008wang · Apr 19, 2016 · 4100 views
    This topic created in 3677 days ago, the information mentioned may be changed or developed.
    比如有多篇文章,要维护这样一个有层级的 id ,类似如下

    1 aa (层级 文章标题)
    1.1 aab
    1.1.1 aab
    1.1.2 aab
    1.2 bb
    1.2.1 dd
    2 dd
    2.1 dd
    2.1.1 xx

    对于文章进行增加,删除,修改, id 要相应变化
    比如删掉 1.1 那么后面的 1.1.1 要变成 1.1 , 1.1.2 变成 1.2
    任意位置增加和删除也要维护这么一个层级的 id

    有什么比较简便的方法吗?
    5 replies    2016-04-19 15:06:03 +08:00
    ibigbug
        1
    ibigbug  
       Apr 19, 2016
    问你一个问题,按照这个说法。 1.1 和 1.2 在删除 1 之后会变成什么样呢?在 2.x 存在的情况下。
    xi2008wang
        2
    xi2008wang  
    OP
       Apr 19, 2016
    如果删除 1
    1.1 会变成 1
    1.2 变成 2
    后面 id 跟着都变化

    刚刚查来一下,可能是用 django-mpp , 正在看文档
    xi2008wang
        3
    xi2008wang  
    OP
       Apr 19, 2016
    打错: django-mpt
    WangYanjie
        4
    WangYanjie  
       Apr 19, 2016
    @ibigbug 诚如你所言,建议楼主画个流程图。

    能想到的只有取的动态生,放缓存
    sxmman
        5
    sxmman  
       Apr 19, 2016
    添加一个 key ,指向父标题,如果是 NULL ,则本身就是 ROOT 标题了;
    添加一个 KEY ,存储在当前 LEVEL 的 index ,取出后根据 index 排序得到最终数字后缀?结合父标题类似生成的标题编码, 生成最终的标题?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5521 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 49ms · UTC 07:43 · PVG 15:43 · LAX 00:43 · JFK 03:43
    ♥ Do have faith in what you're doing.