I’m using Django with Python (but I don’t think that’s relevant; I just need an idea of how to do this,) and I’m wondering how to combine posts from individual users into one feed. For example, user a is ‘following’ (subscribing to) people b, c and d. There are also other users such as e, which person a is not following. Other users, such as b and c can also follow other users. A user can follow no people, some people, or all people.
I want to select all posts by the people user a is following, in order of date. All the posts are stored in a PostgreSQL table called user_post, with the columns id, user_id, content and time.
Is there any way I can do this efficiently? I know websites like Twitter, tumblr, and Facebook do this. I’m not looking for a Python specific example.
You can do this pretty easily with the
inlookup.You just need to get the id’s of the users being followed, then query all posts with those users as an author. Here is some rough code considering I don’t know your Model scheme.