models.py
class Post(models.Model):
post_created_user = models.ForeignKey(User, on_delete=models.CASCADE)
post_name = models.CharField(max_length=100)
--------other------
class FollowersAndFollowing(models.Model):
"""
List of followers and following
"""
followed_by = models.ForeignKey(User, on_delete=models.CASCADE, related_name='followed_by')
followed_to = models.ForeignKey(User, on_delete=models.CASCADE, related_name='followed_to')
created_date = models.DateTimeField(blank=True, null=True)
def __str__(self):
return self.followed_by.first_name + '-' + str(self.followed_to.first_name)
views.py
## query to get all following users list
user_ids = FollowersAndFollowing.objects.filter(followed_by=request.user).values_list('id',flat=True)
## now search for all posts
Post.objects.filter(post_created_user__in = user_ids)