Comparing values from multiple tables; *show new posts* forum feature

0 views
Skip to first unread message

Piotr Husiatyński

unread,
Jan 18, 2009, 5:48:32 AM1/18/09
to Django users
Hello,
I'm writing forum and I have a problem with *show new posts* feature.
Here's the code of my application:

http://github.com/husio/arch-pl/tree/09234f6d780c76b45b5e1a6576d80080507873d4/forum

I have two tables for *new* posts
- AllVisited for marking all posts as visited
- VisitedThread for remembering each post that user has seen

Line ~70 of view.py file is the incomplete question

dt = search_date_limit
unreaded = Thread.objects.filter(
Q(latest_post_date__gt=dt),
Q(visitedthread__isnull=True) |
Q(visitedthread__isnull=False,
visitedthread__date__lt= ? ) #
thread__latest_post_date ?
).distinct()[offset:offset + number]

The only thing I don't know how to do is how to check each
Thread.latest_post_date value during sql select and compare it with
VisitedThread.date value. How to write it?

Malcolm Tredinnick

unread,
Jan 18, 2009, 6:06:07 AM1/18/09
to django...@googlegroups.com

Wait a few days until ticket #7210 is resolved and you'll be able to use
references to other fields as rhs values in filters. The work for that
is nearly complete, so it's pretty close to being committed. I'm fairly
sure that will help you there.

Regards,
Malcolm


Piotr Husiatyński

unread,
Jan 23, 2009, 2:19:31 AM1/23/09
to Django users
On 18 Sty, 12:06, Malcolm Tredinnick <malc...@pointy-stick.com> wrote:
> Wait a few days until ticket #7210 is resolved and you'll be able to use
> references to other fields as rhs values in filters. The work for that
> is nearly complete, so it's pretty close to being committed. I'm fairly
> sure that will help you there.

You mean #7210 http://code.djangoproject.com/ticket/7210 : "Added
expression support for QuerySet.update"
How that could solve my problem?

Russell Keith-Magee

unread,
Jan 23, 2009, 5:06:50 AM1/23/09
to django...@googlegroups.com

#7210 gives you the ability to reference a field as the 'value' part
of a filter clause. So in your case, you could do something like:

Thread.objects.filter(latest_post_date__gt=F('visted_date")

to get all the objects where the latest post is after the visited date.

Yours
Russ Magee %-)

Reply all
Reply to author
Forward
0 new messages