The query you want is like so (from the docs):
from django.db import models
class City(models.Model):
# ...
pass
class Person(models.Model):
# ...
hometown = models.ForeignKey(City)
class Book(models.Model):
# ...
author = models.ForeignKey(Person)
And then your query is:
b = Book.objects.select_related('author__hometown').get(id=4)
p = b.author # Doesn't hit the database.
c = p.hometown # Doesn't hit the database.
b = Book.objects.get(id=4) # No select_related() in this example.
p = b.author # Hits the database.
c = p.hometown # Hits the database.
except in your case your query would be: Picture.objects.select_related('author__blog').get(picture_name='somefilename.jpg')
You're saying I want the picture (and while your at it, the Author and their Blog) that relates to the picture name 'somefilename.jpg'. At least if I've understood your question and DB structure it is.