I want to get all Blogs
in one query, and at the same time, I want to know each Blog's Entry(or Entries), if the Blog has.
class Blog(models.Model):
name = models.CharField(max_length=100)
tagline = models.TextField()
class Entry(models.Model):
blog = models.ForeignKey(Blog)
headline = models.CharField(max_length=255)
Like access the blog.ENTRY attributes. Here is the way come to mind at first. 1) get all Blogs, 2) set each Blog ENTRY attr with its entries:
for blog in Blog.objects.all():
entry = Entry.objects.filter(blog=blog)
setattr(blog, 'ENTRY', entry)
But I want to do this in just one query, because I don't want to do Entry filter query in the for loop.