This is the model:
class Category(models.Model):
name = models.TextField()
class Post(models.Model):
category = models.ForeignKey(Category)
Now, I want to get posts of a category:
category = Category.objects.get(id=1)
posts = category.post_set.all()
# this line hit the DB
posts = category.post_set.all()
# and this line hit the DB again!
How to use the cached result in these relations. I use Django rest-framework and it makes DB hit multiple times for each instance.