Earlier quoted context omitted.
Right, but the better way to actually write this is something like entry = Entry.objects.filter(blog__id=1, entry_number=1).first() if entry is None: # deal with does not exist Maybe it's my scala/Java background shining through, but we are big Django users and we ban the "catch exceptions as standard" workflow, because there is almost always a cleaner way...
This fails to raise an error if there is more than one object matching the given filters
Generally speaking, I tend toward the cleanest code being:
blog = Blog.objects.get(id=1)
entry = blog.entry_set.filter(entry_number=1).first()
if entry is None:
handle_missing_entry()
handle_entry(entry)
But it does suffer from having the extra DB query in there, which may or may not be helpful, depending on the surrounding code (and whether or not you'll be using the blog instance anywhere else).