推荐学习书目
› 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
yangxg
V2EX  ›  Python

django 如何实现按照评论的最后回复时间排序?

  •  
  •   yangxg · Dec 15, 2016 · 3874 views
    This topic created in 3612 days ago, the information mentioned may be changed or developed.

    比如 V2EX 这样,当有人顶了这个帖子时,这个帖子就会排到最前面。

    TKKONE
    TKKONE
    PRO
    Dec 15, 2016❤️1
    1
    没用过 django ,不过有种设想,给评论单独设计一个表,然后评论表有个 id 关联 post ;然后评论表的 primary key 为自增 id ,最后根据自增 id 对 post 排序。。。我觉得可实现
    cute
    cute
    Dec 15, 2016❤️1
    2
    帖子表里记录最后回复的时间
    yangxg
    yangxg
    OP
    Dec 16, 2016
    3
    @cute
    @tumbzzc 谢谢,解决了。 django 的 orm 系统支持跨表查询和数据库函数,于是我查出这篇帖子的全部评论然后取评论发布时间的 max 值,用这个值排序就实现了。
    gogobody
    gogobody
    Dec 16, 2016 via Android
    4
    我好懒,直接用多说了😁
    yangxg
    yangxg
    OP
    Dec 16, 2016
    5
    @gogobody 哈哈,简单的需求用多说还可以,自己写便于定制。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2596 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 14:09 · PVG 22:09 · LAX 06:09 · JFK 09:09
    ♥ Do have faith in what you're doing.