If I have two models in Django:
class Blog(models.Model):
author = models.CharField()
class Post(models.Model):
blog = models.ForeignKey(Blog)
And I want to get all posts for a given blog:
Blog.objects.get(author='John').post_set
If there is a Blog with author='John' but not posts, a DoesNotExist exception is raised. What is the best solution to this? I can do a try: except: on the front-end, a custom manager method, or is there a way to generally override Django to return an empty set. For my purposes, DoesNot Exist isn't useful.
Alternately, the whole issue can be sidestepped with:
Blog.objects.select_related('post').get(author='John').post_set.values()