Home  >  Q&A  >  body text

python - Django orm 使用 求助。

现在已知一个
论坛贴子表BBS
置顶帖子表TOPBBS,外键为BBS的ID

现在想取出最新的5个帖子,现在

BBS.objects.all().order_by('-created_time')[0:5]

但是我想排除一下TOPBBS中的BBS,

因为论坛想先显示TOPBBS,然后再显示最新的帖子,考虑到,不能TOPBBS和最新的BBS不能重复。。

不知道该怎么写。
我知道exclude,但是不知道怎么关联到TOPBBS去写。

除了这种还有别的处理方式没。

插一句,orm用习惯了好好用啊。半吊子的时候,最痛苦

天蓬老师天蓬老师2712 days ago260

reply all(1)I'll reply

  • 怪我咯

    怪我咯2017-04-17 17:35:49

    There is something wrong with your table design, so you are confused.

    Question: What is the difference between ordinary posts and pinned posts?

    Except for whether to pin it to the top, it’s almost the same.

    Then, these two things should be in one table, distinguished by a field is_top

    The problem is solved

    reply
    0
  • Cancelreply