python - Django orm 使用 求助。
天蓬老师
天蓬老师 2017-04-17 17:33:49
0
1
259

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

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

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

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

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

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

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

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

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(1)
刘奇

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!