hi there,
i want to make a 'timeline' containing all mini blog posts from a user, and all the user he is following. I want all these posts to be ordered by date..But how can i 'join' the posts, because the 'following' relation is in another table, so i have to make some kind of a join between the two tables, for taking the data.
For now, in my 'timeline', there appears only the blog posts of the owner of the blog,and i user a query like:
blog = New.objects.filter(created_by = request.user)
but i want to join there posts with the posts of the persons he is following, meaning:
following = Relations.objects.filter(initiated_by = request.user)
where Relations is the 'Follow relation' table.
how can i do it? thank you!
my models:
class New(models.Model):
post = models.CharField(max_length=120)
date = models.DateTimeField(auto_now_add=True)
created_by = models.ForeignKey(User, blank=True)
objects = NewManager()
class Relations(models.Model):
initiated_by = models.ForeignKey(User, editable=False, related_name = 'initiator')
date_initiated = models.DateTimeField(auto_now=True, editable = False)
follow = models.ForeignKey(User, editable = False, related_name = "follow")
date_follow = models.DateTimeField(auto_now=True, editable = False)